728x90
반응형

list 3

[Python] List comprehension, 리스트 컴프리헨션

https://www.hackerrank.com/challenges/nested-list/problem Nested Lists | HackerRank In a classroom of N students, find the student with the second lowest grade. www.hackerrank.com 이 문제를 기반으로 설명한다. 여기서 쓰인 것을 List comprehension이라고 하는데 책에는 잘 안나와서.. 어려울 수 있다. for문을 쓸 때 앞에 아무것도 안 붙이니까!! 그래서 LIne 6을 보면 어떤가 보니 for name, marks in marksheets // 즉 marksheets에 들어있는 것들을 name, marks 라는 변수로 차례대로 불러들일 거고 그 중 m..

[Python] 리스트 응용하기

https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list/problem Find the Runner-Up Score! | HackerRank For a given list of numbers, find the second largest number. www.hackerrank.com 이 문제를 기반으로 설명했다. 사실 pop으로 할 수 있을 줄 알았다. 그렇지만 무작위로 리스트가 만들어졌기 때문에 2번째로 큰 값을 알기 위해서 정렬을 해도 괜찮았지만 다른 방법인 remove를 찾기로 했다. 최댓값이 바뀔 때까지 최댓값을 삭제하는 것이다. 다른 방법으로는 중복을 방지하려고 set으로 바꿨다 다시 list로 바꿀 수 있다. 뭐가 더..

[Python] 집합과 리스트, Set&List

https://www.hackerrank.com/challenges/py-introduction-to-sets/problem Introduction to Sets | HackerRank Use the set tool to compute the average. www.hackerrank.com 이 문제를 기반으로 집합은 중복 원소를 허용하지 않는다. 리스트는 중복을 허용한다. 그래서 리스트 입력을 받아서 계산할 때는 집합으로 해야할 때가 있다. 그 때는 저렇게 하는 것이다. 그리고 ** arr = list(map(int, input().split())) 문장이 중요하다 문자열로 입력을 받지만 int형으로 바꿔서 리스트로 받는 형태이다. map()에 대해서 더 공부하는 것이 좋겠다.

728x90
반응형