FAQ: Learn Python: Python Lists and Dictionaries - This Next Part is Key

This community-built FAQ covers the “This Next Part is Key” exercise in Codecademy’s lessons on Python.

FAQs for the Codecademy Python exercise This Next Part is Key:

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).

A post was split to a new topic: Why does this give me a Key error

What is the difference between dictionaries and lists nested within lists?

The first big difference is how the data is structured, for one. Lists may contain repeated data, while dictionaries are like sets, no keys alike. The data associated with each key may be similiar or identical, but the keys are all unique.

Dictionaries are easy to query. Poll a key and out pops its associated value.

dict[key] => value

Polling a list for a particular piece of data requires iteration (or some special tool such as a find() method, etc.)

1 Like

So I used this code :

listo = [‘well’,‘lets’,‘see’]

residents = {‘Puffin’ : listo, ‘Sloth’ : 105, ‘Burmese Python’ : 101}

print residents

and the output was : {‘Sloth’: 105, ‘Puffin’: [‘well’, ‘lets’, ‘see’], ‘Burmese Python’: 101}

My question is, why didn’t the ‘Puffin’ get printed before ‘Sloth’ even though that is how the dictionary is defined?

Previous to Python 3.5 insertion order is not retained. Dictionaries do not need to be ordered, or least didn’t need to be for most purposes since they have no duplicate keys.

1 Like

Are disctionaries the Python equivalent to javascript objects?

For the most part they are both associative arrays. Each language provides its own support through various methods for accessing and modifying them. The thing they have in common is key-value pairs in no particular order. The keys are immutable and unique. The values may be any data type.

1 Like