Use a Dictionary Key to Retrieve a Value
Look up the exact supplied key and report its associated value.
About 18 minutes, plus any extended practice
Supplied materials
- Paper and pencil; answers may also be spoken or typed.
- All cases, labels, numbers and rules are supplied on this page. No real account, private information or purchase is needed.
Learn the idea
A Python dictionary associates keys with values. A key identifies the requested association rather than a row position. Different keys can have equal values without being the same key. The cases provide present keys only so no missing-key error is hidden in the answer.
Look up the exact supplied key and report its associated value. Do not retrieve a dictionary value by guessing list-like row order.
Use this supplied case: Paper Python 3 expression: {"a":4,"b":7}["a"]. What value results? The task is to connect the given information to the computing idea. Write a short evidence trail so another learner can reproduce your choice. The simplified case describes the stated model, not every real system.
- Represent the supplied worked case with a labeled drawing, table or short trace.
- Look up the exact supplied key and report its associated value.
- Explain why the worked answer fits and why one alternative does not.
- Try the new check and practice cases; revisit the stated rule if your evidence does not match.
See the method in action
The dictionary {"apple":12,"pear":5} associates key "apple" with 12 and key "pear" with 5. Looking up "pear" returns 5; looking up "apple" returns 12. This operation uses a named key rather than an entry’s display position. Equal values under different keys would still be different associations. These requested keys exist; an absent key would need a separately specified handling rule.
Check your reasoning
Your answer is temporary and is not saved to an account. Download your current answer before leaving or reloading. Written work on paper or in another app stays in your own file.
Helpful tips
- Look up the exact supplied key and report its associated value.
- Do not retrieve a dictionary value by guessing list-like row order.
See the answer and explanation
7
The requested key is 'b'. The supplied dictionary maps that key to 7; this is a key lookup, not a numbered position. Look up the exact supplied key and report its associated value.
Take it further
For lookup={"A":6, "B":6}, expected lookup["B"]=6. Equal values do not make A and B the same key.
Nothing here is saved to an account or sent to a teacher. The answer download includes your current choice and any checked feedback. It does not include choices from the separate More practice section. Download that section separately.
More practice: try new cases
Choose an answer for each problem. Explain your method on paper, then use the feedback to decide what to revisit.
Your choices are temporary. Feedback appears after you check all the answers.
Nothing here is saved to an account or sent to a teacher. Keep your own notes or download them before leaving. The score describes these questions; it does not certify subject mastery.
Check the subject sources
These LifeStarter passages, scenarios and exercises are authored for this Academy with AI assistance and review. External resources keep their publishers’ terms. A grade label suggests a starting level; it does not establish alignment with your school’s complete requirements.