코드
def solution(files):
answer = []
res=[]
for f in files:
head=''
number=''
for i in range(len(f)):
if f[i].isdecimal():
number+=f[i]
elif not f[i].isdecimal():
if number!='':
break
head+=f[i]
if i==len(f)-1:
res.append([head,number])
else:
res.append([head,number,f[i:]])
res=sorted(res, key=lambda x: (x[0].lower(),int(x[1])))
for s in res:
answer.append(''.join(s))
return answer
다른 사람의 풀이
import re
def solution(files):
a = sorted(files, key=lambda file : int(re.findall('\d+', file)[0]))
b = sorted(a, key=lambda file : re.split('\d+', file.lower())[0])
return b