Dictionaries
Mutability
Adding a key-value pair
touch src/dicts.py tests/test_dicts.pyfrom src.dicts import add_item_to_dict
class TestDicts:
def test_item_can_be_added(self):
"""
Given an empty dictionary
And a new key value pair to be added
When `add_item_to_dict()` is called
Then the returned dictionary contains the key-value pair
"""
# Given
items = {}
new_key = "abc"
new_value = 123
# When
items = add_item_to_dict(items=items, key=new_key, value=new_value)
# Then
assert new_key in items
assert items[new_key] == new_valueDe-duplicated key value pairs
Looking up items
Accessing key value pairs
Summary
References
Last updated