I have a dictionary of dog owners and i need to write a function update_age()
that will update the dogs owner's ages in the dictionary. Here is an example:
dog_owners = {("John", "Malkovic", 22): ["Fido"],
("Jake", "Smirnoff", 18): ["Butch"],
("Simon", "Ng", 32): ["Zooma", "Rocky"],
("Martha", "Black", 73): ["Chase"]}
So the key is a tuple in which the numbers 22, 18, 32, and 73 represent age.
The function update_age()
has 3 arguments: name of dictionary, tuple with 3 elements, the number that should change the number from the tuple.
Example:
update_age(dog_owners, ("Jake", "Smirnoff", 18), 22)
dog_owners[("Jake", "Smirnoff", 22)] == ['Butch']
dog_owners.get(("Jake", "Smirnoff", 18)) is None
I tried to do:
def update_age(owners, owner, new_age):
b = (new_age,)
return owner[0:2] + b
but it is not correct because the original key still has the previous value and if i write:
print(update_age(dog_owners, ("Jake", "Smirnoff", 18), 22)) # for check
print(dog_owners.get(("Jake", "Smirnoff", 18)) is None)
the answer will be
('Jake', 'Smirnoff', 22)
False
So it means that my original key still has its previous value. How can I change it? May be I should try pop()
and than add a new tuple to the key, but I don't know how.