Python: Difference between revisions

65 bytes removed ,  22 January 2020
Line 230: Line 230:
# Check if a key is in a dictionary
# Check if a key is in a dictionary
# O(1)
# O(1)
d = {'1': 'one', '3': 'three', '2': 'two', '5': 'five', '4': 'four'}
"1" in my_map
"1" in d


# Check if a value is in a dictionary
# Check if a value is in a dictionary
# Usually you should have a second dictionary if you need this functionality
# Usually you should have a second dictionary if you need this functionality
# O(n)
# O(n)
'one' in d.values()
'a' in d.values()
</syntaxhighlight>
</syntaxhighlight>