수량 카운트 프로그램
# 제품 수량 카운트 프로그램 # 리스트 배열 name = ["note", "pen", "note", "note", "pen", "ballpen", "eraser", "eraser"] d = {} # dictionary를 만든다. for i in name: if i in d: # "note"라는 key가 dictionary에 들어 있어? d[i] = d[i] + 1 # "note"가 있다면 수량 하나를 up해줘! else: # 만약에 "note"가 없다면 d[i] = 1 # dictionary에 넣고, value는 1로 해줘! print(d) # 출력 # 결과값: {'note': 3, 'pen': 2, 'ballpen': 1, 'eraser': 2}
2019.08.20