알고리즘/프로그래머스
[파이썬][프로그래머스] Lv. 2 튜플
SBOX Learning by doing
2022. 7. 20. 00:43
반응형
import re
def solution(s):
answer = []
count = {}
# 숫자면 카운트
temp = ''
s = s.split(',')
# 숫자만
for i in s:
i = re.sub(r'[^0-9]', '', i)
if i in count.keys():
count[i] += 1
else:
count[i] = 1
# 딕셔너리 전환
count_list = {}
for key, value in count.items():
count_list[value] = key
# 결과값
for i in range(len(count_list), 0, -1):
answer.append(int(count_list[i]))
return answer
반응형