본문 바로가기

BOJ/Python

[BOJ] 1181. 단어 정렬

*정렬 조건을 두 개로 정한다. 

lambda로 단어의 길이 / 단어 사전순 오름차순으로 정렬하도록 한다. 

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
import operator
n = int(input())
 
word = {}
for _ in range(n):
    tmp = input()
    word[tmp] = len(tmp)
 
 
sortWord = sorted(word.items(), key=lambda x : (x[1],x[0]))
 
for i in sortWord:
    print(i[0])

'BOJ > Python' 카테고리의 다른 글