In Python, the map
data structure is called a dictionary
. To find the value associated with a key in a Python dictionary, you can simply use the key as an index:
main.py107 chars3 lines
If the key is not present in the dictionary, this will raise a KeyError
. To avoid this, you can use the .get()
method, which returns None
if the key is not present:
main.py109 chars3 lines
You can also provide a default value to the .get()
method, so that it returns the default value instead of None
:
main.py135 chars3 lines
gistlibby LogSnag