알고리즘
[Python] 알고리즘 문제풀이 팁) 리스트에 있는 데이터 수 파악하고 싶은 경우 (python list-list, list+list)
xyz1
2022. 9. 20. 23:11
from collections import Counter
list1 = ["a", "b", "c", "d"]
list2 = ["a", "b", "c"]
answer = Counter(list1) - Counter(list2)
# 출력: Counter({'d': 1})
answer = Counter(list1) + Counter(list2)
# 출력: Counter({'a': 2, 'b': 2, 'c': 2, 'd': 1})