Introduction


Untitled

Almost all of types of values can be used as dictionary key with Python. We just saw this example, where the object is integer, float, and Boolean is used as the key.

There are some limitations that must be followed by dict key.

Restriction in Value


Its vice versa, there is no such limitation on dict value. Literally there is nothing. dict Value can be all of object types that is supported by Python. It is including the type that can be changed such as list and dict and object that is determined by the user. There is no limitation as well toward certain value that emerge in dict sometimes.

Untitled

Implementation


foo = {42: 'aaa', 2.78: 'bbb', True: 'ccc'}

d = {int: 1, float: 2, bool: 3}

d = {bin: 1, hex: 2, oct: 3}
{'Liverpool': 'Liverpool',
 'Chelsea': 'London',
 'Manchester United': 'Manchester',
 'Manchester City': 'Manchester',
 'Arsenal': 'London',
 'New Castle United': 'New Castle',
 'West Ham United': 'Birmingham'}

**key dict**must immutable