[파이썬을 파이썬답게] 가장 많이 등장하는 알파벳 찾기
my dirty code with for x 2 from collections import Counter my_str = input().strip() c = Counter(my_str).most_common() max_num = 0 for k, v in c: if v > max_num: max_num = v res = "" for k, v in c: if v == max_num: res+=k print("".join(sorted(res))) import collections my_list = [1, 2, 3, 4, 5, 6, 7, 8, 7, 9, 1, 2, 3, 3, 5, 2, 6, 8, 9, 0, 1, 1, 4, 7, 0] answer = collections.Counter(my_list) print(..
2021. 3. 8.
[파이썬을 파이썬답게] 곱집합 구하기 - itertools.product
itertools.product for 문 사용하지 않고 product 구하기 import itertools iterable1 = 'AB' iterable2 = 'xy' iterable3 = '12' print(list(itertools.product(iterable1, iterable2, iterable3))) # output # [('A', 'x', '1'), ('A', 'x', '2'), ('A', 'y', '1'), ('A', 'y', '2'), ('B', 'x', '1'), ('B', 'x', '2'), ('B', 'y', '1'), ('B', 'y', '2')] 리스트로 해줘야 함
2021. 3. 8.