파이썬 리스트 안의 항목 개수 세기
조회수 2012회
num=[1,2,2,3,3,4,4,4,4,4] 이 리스트안에 중복되는 항목들의 개수를 어떻게 셀 수 있을까요? count함수 이용하면 안되고 for반복문을 사용하여 세야합니다.
-
(•́ ✖ •̀)
알 수 없는 사용자
1 답변
-
num = [1,2,2,3,3,4,4,4,4,4] # for statement for n in num: print(n) # dictionary d = { 'a': 1, 'b': 2 } # exist or not exist in a dictionary print('a' in d) # True print('c' in d) # False print('c' not in d) # True # set k-v to a dict d['c'] = 3 print('c' in d) # True # if-else statement if ('c' not in d): print('c is not exist in a dict') else: # get a value from a dict print(d['c']) # 3 # increment d['c'] += 1 print(d['c']) # 4
위 개별 문법들을 조합하면 됩니다.
댓글 입력