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

collections 모듈 - ChainMap 클래스(class)


/// 설명

여러 딕셔너리들이나 다른 매핑들을 함께 하나로 만들어주는 클래스입니다. 맵(map)이 주어지지 않는다면 빈 딕셔너리 하나가 생성됩니다. 이 맵핑들은 리스트에 저장됩니다.

※ 형식
class collections.ChainMap(*maps)

/// 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import collections
 
test_cm = collections.ChainMap()
 
print(test_cm)  # ChainMap({})
print(type(test_cm))  # <class 'collections.ChainMap'>
 
test_dict1 = {'a'1'b'2'c'3}
test_dict2 = {'d'4'b'5'e'6}
 
test_cm = collections.ChainMap(test_dict1, test_dict2)
 
print(test_cm)  # ChainMap({'a': 1, 'b': 2, 'c': 3}, {'d': 4, 'b': 5, 'e': 6})
 
# the iteration order is determined by scanning the mappings last to first.
print(list(test_cm))  # ['d', 'b', 'e', 'a', 'c']
 
cs

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


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

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

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

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

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

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