Hi everyone,

I'm trying to write some code for this question. I believe I have the right answer but it says it isn't.

Anyways here is the question.

1) Given that dict1 refers to a dictionary, change the value mapped to by the key 'Boo' to 'Hoo' .

My code is:

dict1['Hoo'] = dict1['Boo']

Thanks in advance

No,that doesn't quite work. What you would be doing is assigning the key 'Boo' to have the same value as they key 'Hoo'. The question wants you to change the value of dict1 to 'Hoo'

>>> mydict = { 'bar':'none', 'Boo':'something' }
>>> print mydict['Boo']
something
>>> mydict['Boo'] = 'Hoo'
>>> print mydict
{'bar': 'none', 'Boo': 'Hoo'}
>>> print mydict['Boo']
Hoo

Edited 7 Years Ago by mn_kthompson: n/a

Oh it was actually a lot simplier than I expected haha... Dang I misread it a lot :/

Thanks

No,that doesn't quite work. What you would be doing is assigning the key 'Boo' to have the same value as they key 'Hoo'. The question wants you to change the value of dict1 to 'Hoo'

>>> mydict = { 'bar':'none', 'Boo':'something' }
>>> print mydict['Boo']
something
>>> mydict['Boo'] = 'Hoo'
>>> print mydict
{'bar': 'none', 'Boo': 'Hoo'}
>>> print mydict['Boo']
Hoo
This question has already been answered. Start a new discussion instead.