Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

jessicamurr
jessicamurr
3,313 Points

Can you update the keys without changing the values?

In the video Update and Mutate Dictionaries, we update the values of the keys by passing the key:

course['teacher'] = 'Treasure'

However, what if I wanted to change the key itself instead of changing the value of that key? Like if I wanted to change 'teacher' to 'professor' while keeping the value the same?

Thanks for your help!

1 Answer

Steven Parker
Steven Parker
229,644 Points

You can't change a key, but you can create a new key and assign it the value of the old one, then delete the old key.