jm_p_op
.py dictionary , sorted 본문
test={"b":4,"c":4,"a":4,"e":5,"d":6}
print("쾅운킹",sorted(test.items(), key=lambda item: item[1] ,reverse=True))
#[("d",6),("e",5),("b",4),("c",4),("a",4)]
test={"b":0,"c":4,"a":4,"e":5,"d":6}
print(sorted(test,reverse=True)) # sorted(dict,reverse=True) 의 경우 value값으로 1차 정렬, key값으로 2차 정렬
# ['e', 'd', 'c', 'b', 'a']
딕셔너리의 정렬은 value값으로 정렬한후, key값을 정렬한다
'py' 카테고리의 다른 글
.py SpeechRecognition 3.10.0 import에러 (0) | 2023.05.23 |
---|---|
.py 실험실 공간할당(list붙이기) (0) | 2023.05.06 |
.py Truthy&Falsy (if type) (0) | 2023.04.05 |
.py try문과 class-object와 funtion 사이에 일어나는 일(실험실) (0) | 2023.04.04 |
.py dictionary를 class에 넣기 , ** 언어 (0) | 2023.04.03 |