포스트

[Python] 백준 10807번 - 개수 세기

Python map 객체 특성, list() 변환을 통한 리스트 객체 활용법

For the English version of this post, see here.
[Python] 백준 10807번 - 개수 세기

BaekJoon 10807

풀이

1
2
3
4
5
6
7
8
9
10
11
num = int(input())
arr = list(map(int, input().split()))
    
v = int(input())

cnt = 0
for i in range(num):
    if arr[i] == v:
        cnt += 1
        
print(cnt)

map의 결과

  • list가 아니라 map 객체임 ex) <map object at 0x...>
  • 따라서 list()로 감싸서 list로 만들어줘야함

댓글

궁금한 점, 피드백, 오류 제보를 남겨 주세요.