.sort() 썸네일형 리스트형 [python] 단어 리스트 단어길이순, 단어순 정렬하기 단어 리스트 단어길이순, 단어순 정렬하기 txt = 'but soft what light in yonder window breaks'words = txt.split()t = list()for word in words: t.append((len(word), word)) t.sort(reverse=True) res = list()for length, word in t: res.append(word) print res 단어를 리스트에 담을때 길이도 같이 담는다. .sort() 는 첫번째 요소를 정렬하고 첫번째 요소가 동일하면 두번째 요소를 정렬한다. reverse=True 는 내림차순(큰것에서 작은것)으로 정렬해준다. * 파일에 저장하기with open( "./단어장파일.txt", "w", encoding='.. 더보기 [python] Python List sort() Method Python List sort() Method * 오름차순이 .sort(), 내림차순은 .sort(reverse=True) DescriptionThe method sort() sorts objects of list, use compare func if given.SyntaxFollowing is the syntax for sort() method −list.sort([func])ParametersNAReturn ValueThis method does not return any value but reverse the given object from the list.ExampleThe following example shows the usage of sort() method.#!/usr/bin/python .. 더보기 이전 1 다음