Python 문자열 정렬에 대하여


Python 문자열 정렬에 대하여

파일 이름이 포함된 문자열 목록이 있다. flist = ['0.png','10.png', '3.png', '4.png', '100.png'] flist.sort() print(flist) 결과 ['0.png', '10.png', '100.png', '3.png', '4.png'] 문자열은 정렬을 할때 사전 순으로 정렬이 된다. 그러므로 "10"이 "3" 보다 앞에 온다. 아래와 같이 실행하면 flist.sort(key=lambda fname: int(fname.split('.')[0])) - 오름차순으로 정렬된다. ['0.png', '3.png', '4.png', '10.png', '100.png'] https://stackoverflow.com/questions/52737587/sorting-a-list-of-strings-numerically Sorting a list of strings numerically I have a list of strings with my filena...



원문링크 : Python 문자열 정렬에 대하여