문제
me
def solution(strings):
strings = strings.split('}')
answer =[]
for i,string in enumerate(strings):
strings[i]= string.strip('{').strip(',').strip('{').split(',')
strings.sort(key=lambda x:len(x))
for string in strings:
if string == ['']: continue
for s in string:
if s in answer:
if string.count(s)>answer.count(s):
answer.append((s))
else:
answer.append((s))
return [ int(a) for a in answer]
others
def solution(s):
s = Counter(re.findall('\d+', s))
return list(map(int, [k for k, v in sorted(s.items(), key=lambda x: x[1], reverse=True)]))
import re
from collections import Counter
def solution(s):
answer = []
s1 = s.lstrip('{').rstrip('}').split('},{')
new_s = []
for i in s1:
new_s.append(i.split(','))
new_s.sort(key = len)
for i in new_s:
for j in range(len(i)):
if int(i[j]) not in answer:
answer.append(int(i[j]))
return answer
- key = len 하면 알아서 길이대로 정렬해줌
- 근데
중복된 원소가 있을 수 있습니다. ex : (2, 3, 1, 2)
이 조건에 반하는 것이 아닌가??