[파이썬] 딕셔너리(dictionary) key(키) 또는 value(값) 순으로 정렬하기
dict = {'apple': 3, 'banana': 2, 'cherry': 1}# key 순으로 정렬sorted_d = sorted(dict.items())( sorted_d = sorted(dict.items(), key=lambda x: x[0]) )print(sorted_d)# [('apple', 3), ('banana', 2), ('cherry', 1)]# value 순으로 정렬sorted_d = sorted(dict.items(), key=lambda x: x[1])print(sorted_d)# [('cherry', 1), ('banana', 2), ('apple', 3)]# 내림차순으로 정렬 (숫자만 가능! str은 안됨!)( sorted_d = sorted(dict.items(), key=..