문제: https://www.acmicpc.net/problem/1181
풀이
풀면서 두 가지를 배웠다.
- 리스트에서 중복을 제거하려면 list(set(리스트 이름))을 하면 된다.
(set에서 중복이 제거되기 때문. 이 문제에서는 정렬을 위해 리스트 형태가 필요하므로 다시 리스트로 만든다) - 정렬시 길이순으로 먼저 정렬하고, 그 안에서 사전순으로 정렬하고 싶다면 key 함수의 return 값을 (len(x), x)로 주면 된다.
소스코드
import sys, collections
input = sys.stdin.readline
n = int(input())
vocas = list(set([input().strip() for _ in range(n)]))
vocas.sort(key=lambda x: (len(x), x))
for voca in vocas:
print(voca)