프로그래머스 - 파일명 정렬


프로그래머스 - 파일명 정렬

123456789101112131415161718192021222324def solution(files): renamed = [] cnt = -1 for f in files: re = "" tmp = "" c = 0 cnt += 1 for i in f: if i.isdigit(): tmp += i c = 1 elif not c: re += i.upper() else: break renamed.append([re,int(tmp),cnt,f]) r = sorted(renamed, key=lambda x: (x[0],x[1],x[2])) ans = [] for x in r: ans.append(x[3]) return ansColored by Color Scriptercs files에서 파일명을 가져오며 파일명 내의 캐릭터들을 살펴본다.숫자면 tmp에 저장하고 c를 true로 만든다c가 false이면 re에 문자를 re에 저장c가 true인데 문자가 들어오면 조건을 탈출한다.-> 위 과정에서 생성한 문자(head), 숫자(nu..........



원문링크 : 프로그래머스 - 파일명 정렬