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)