FAQ: Using Dictionaries - Get All Items

This community-built FAQ covers the “Get All Items” exercise from the lesson “Using Dictionaries”.

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

Computer Science

FAQs on the exercise Get All Items

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!

1 Like

In this exercise there is an error in the pct_women_in_position dictionary. It should be “Engineering ManagerS”, and not “Manager”. I got an error because of it. If it’s by design, then ignore this post.

1 Like

it marks ok without any solution and dont know how to solve it since i cant see if everythong is ok or not

A for loop to iterate over a dictionary and print out the key-value looks something like this…

for key in dictionary:
    print ("Women make up {percentage} percent of {occupation}.".format(percentage=dictionary[key], occupation=key))

The above iterates over only the keys in the dictionary, so we need to subscript it to poll the value.

If this lesson is about dict.items() then the loop will look like so,

for key, value in dictionary.items():
    print ("Women make up {percentage} percent of {occupation}.".format(percentage=value, occupation=key))

The above works because it is unpacking a tuple on each iteration. If we examine the array that items() returns we can see the tuples…

[
  ('CEO', 28), 
  ('Engineering Manager', 9), 
  ('Pharmacist', 58), 
  ('Lawyer', 37), 
  ('Aerospace Engineer', 9)
]

https://repl.it/@mtf/Get-All-items

1 Like

thank you! that makes all sense now

1 Like

had this issue as well