Build up a good understanding for dictionaries as a data structure and find use cases where it shines.
Dictionary (dict)
Definition: Unordered (ordered since Python 3.7), mutable, key-value pairs.
Syntax: my_dict = {'a': 1, 'b': 2}
Common operations & properties:
- Access:
my_dict['a']
- Add/Update:
my_dict['c'] = 3
- Delete:
del my_dict['b']
- Keys/Values:
my_dict.keys(), my_dict.values()
- Items:
my_dict.items()
- Get with default:
my_dict.get('d', 0)
Build up a good understanding for dictionaries as a data structure and find use cases where it shines.
Dictionary (dict)
Definition: Unordered (ordered since Python 3.7), mutable, key-value pairs.
Syntax: my_dict =
{'a': 1, 'b': 2}Common operations & properties:
my_dict['a']my_dict['c'] = 3del my_dict['b']my_dict.keys(), my_dict.values()my_dict.items()my_dict.get('d', 0)