Scribbling

Python Immutable Dictionary, Set 본문

Computer Science/Python

Python Immutable Dictionary, Set

focalpoint 2022. 3. 22. 11:36

Immutable dictionary: MappingProxyType

Immutable Set: Frozenset

from types import MappingProxyType

d = {'a': 'apple', 'b': 'banana', 'c': 'carrot'}
d_fixed = MappingProxyType(d)
print(d_fixed['a'])

s = frozenset([1, 2, 3])
print(s)

 

'Computer Science > Python' 카테고리의 다른 글

Python: Design Patterns  (0) 2022.03.25
Python: Memoryview function  (0) 2022.03.23
Python Data Structures: Sequences  (0) 2022.03.21
Python Magic Methods: Pythonic Data Model  (0) 2022.03.16
Python Grammar: Things that I forget often  (0) 2022.03.14