풀이
입력으로 받은 단어를 모두 정렬하고 순서대로 출력합니다.
만약 이전에 출력한 단어와 지금 출력하려던 단어가 같다면 출력하지 않고 다음 단어를 살펴보면 중복을 제거하고 출력할 수 있습니다.
코드
def main():
N = int(input())
words = [input() for _ in range(N)]
words.sort(key=lambda w: (len(w), w))
print(words[0])
for i in range(1, N):
if words[i] == words[i - 1]:
continue
print(words[i])
main()