PYTHON| ChainMap

ChainMap이란?

python docs chainmap Python에서 ChainMap의 실제 사용 체인맵이란 무엇인가요?

ChainMap

공식 문서에 따르면… 여러 매핑을 연결하여 단일 단위로 취급할 수 있도록 하며 종종 새로운 딕셔너리를 만들고 여러 update() 호출하는 것보다 훨씬 빠르다고 한다.

baseline = {'music': 'bach', 'art': 'rembrandt'}
adjustments = {'art': 'van gogh', 'opera': 'carmen'}
list(ChainMap(adjustments, baseline))

해당 코드의 결과는 ['music', 'art', 'opera']이다.

the use cases I know of include

  • Searching through multiple dictionaries
  • Providing a chain of default values
  • Performance-critical applications that frequently compute subsets of a dictionary

자주 사용되지 않지만 알고 있으면 좋긴할 듯하다.


© 2024. All rights reserved.

Powered by Hydejack v9.2.1