FAQ: Learn Python: Python Lists and Dictionaries - Changing Your Mind

Community%20FAQs%20on%20Codecademy%20Python%20Exercises

This community-built FAQ covers the “Changing Your Mind” exercise in Codecademy’s lessons on Python.

FAQs for the Codecademy Python exercise Changing Your Mind:

Join the Discussion. We Want to Hear From You!

Have a new question or can answer someone else’s? Reply (reply) to an existing thread!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources about Python in general? Go here!

Want to take the conversation in a totally different direction? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account, billing, Pro, or Pro Intensive? Reach out to our support team!

None of the above? Find out where to ask other questions here!

Other FAQs

The following are links to additional questions that our community has asked about this exercise:

  • This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
  • Currently there have not been enough questions asked and answered about this exercise to populate this FAQ section.
  • This FAQ is built and maintained by you, the Codecademy community – help yourself and other learners like you by contributing!

Not seeing your question? It may still have been asked before – try (search) in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post (reply).

Hi! in the previous excercise I added dish-price pairs to the menu dictionary. When I wanted to set the ‘Rockhopper Penguin’ value to something else I used the exact same code as when I added new key pairs.

My question is, why does it change the existing pair instead of creating a new ‘Rockhopper Penguin’ pair, similar to what would happen in a list? Can I ever add two keys with the same name but different values in a dictionary?

Thanks in advance!

If you want a list of pairs use… a list… right?
Keys specify what you want, similar to an index in a list. Can you have two values at the same index? If you replace something then you are discarding the old thing.

Yes, but let’s say we create the list pets = [‘dog’, ‘cat’, ‘dog’]. We have ‘dog’ at index [0] and [2]. The same wouldn’t work for the dictionary pets = {‘dog’: 1, ‘cat’: 2, ‘dog’: 3} in my case. Maybe I can .append a ‘dog’ into the dictionary but I haven’t tried yet.

A dictionary isn’t a list, it doesn’t have an append operation. A dict is a key-value store, you can insert values at a key.
You’re using a key as a value so it’s not equivalent is it? You can have multiple values that are dog, nothing’s stopping you from that. The purpose of keys is to refer to a specific value.

If you have two identical street addresses then is that not the same address? You don’t have two, you have one.

If you expect something to behave a like a list… use a list.

[('dog', 1), ('cat', 2), ('dog', 3)]

Or if you want each key to be associated with multiple values, then, how do you represent multiple values? A list. In that case you do not have many dogs, you have a dog key, and a list of values