파일이름 뒤에 f를 붙혀 tail없는 예외를 없앤 후 head, number를 heap에 넣은 후 뽑아내며 정렬 from heapq import heappop, heappush def solution(files): answer = [] sort_arr = [] for pos, each_file in enumerate(files): tmp = each_file + 'f' flag = 0 for idx, char in enumerate(tmp): if not flag and char.isdigit(): start = idx flag = 1 elif flag and not char.isdigit(): end = idx break head, number = each_file[:start], each_file[s..