파이썬[Python]: collections - OrderedDict 클래스

collections 모듈 - OrderedDict 클래스(class)


/// 설명

딕셔너리 순서를 재 정렬하기 위한 특별한 메서드들을 제공하는 dict subclass의 인스턴스를 반환합니다.

※ 형식
class collections.OrderedDict(*maps)

/// 예제

1
2
3
4
5
6
7
8
9
10
11
12
import collections
 
test_dict = {'a'6'b'2'd'3'g'4'c'5'r'3'h'1}
print(test_dict)  # {'a': 6, 'b': 2, 'd': 3, 'g': 4, 'c': 5, 'r': 3, 'h': 1}
 
test_odict = collections.OrderedDict(test_dict)
print(test_odict)
# OrderedDict([('a', 6), ('b', 2), ('d', 3), ('g', 4), ('c', 5), ('r', 3), ('h', 1)])
 
test_r = reversed(test_odict.items())
print(list(test_r))  # [('h', 1), ('r', 3), ('c', 5), ('g', 4), ('d', 3), ('b', 2), ('a', 6)]
 
cs

* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

파이썬[Python]: 내장함수 - from_bytes 메서드

파이썬[Python]: 내장함수 - __len__ 메서드

파이썬[Python]: kivy - 한글 사용

파이썬[Python]: 내장함수 - bit_length 메서드

C 언어: sin 함수, cos 함수, tan 함수