FAQ: Creating Dictionaries - Add Multiple Keys


#1

This community-built FAQ covers the “Add Multiple Keys” exercise from the lesson “Creating Dictionaries”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science

FAQs on the exercise Add Multiple Keys

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

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

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

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

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


#2

user_ids = {“teraCoder”: 9018293, “proProgrammer”: 119238}
user_ids.update({“theLooper”: 138475, “stringQueen”: 85739})
print(user_ids)

When I run the above in Codeacademy the result is:
{‘stringQueen’: 85739, ‘theLooper’: 138475, ‘teraCoder’: 9018293, ‘proProgrammer’: 119238}

When I run the same code in my text editor, the result is:
{‘teraCoder’: 9018293, ‘proProgrammer’: 119238, ‘theLooper’: 138475, ‘stringQueen’: 85739}

Why the difference in the ordering?
The output of my text editor seems more rational to me since the additions are placed after the original content of the dictionary.


#3

because only since python 3.6 dictionaries preserve order