Skip to content
Exercises · Q8

Q.Consider the following dictionary stateCapital:
stateCapital = {"Assam":"Guwahati", "Bihar":"Patna","Maharashtra":"Mumbai", "Rajasthan":"Jaipur"}
Find the output of the following statements:

a) print(stateCapital.get("Bihar"))
b) print(stateCapital.keys())
c) print(stateCapital.values())
d) print(stateCapital.items())
e) print(len(stateCapital))
f) print("Maharashtra" in stateCapital)
g) print(stateCapital.get("Assam"))
h) del stateCapital["Assam"]
print(stateCapital)
Odisha ChseTextbookSubjective· 3mImportance★★★★★est
53% · 16/30 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

get(key) returns the value for a key, keys() / values() / items() return view objects

(printed as dict_keys(...), dict_values(...), dict_items(...)), len() counts key-value pairs,

in tests keys only, and del d[key] removes a whole pair. Since Python 3.7 a dictionary

keeps its insertion order, so every view prints in the order the pairs were created.

The dictionary

stateCapital = {"Assam": "Guwahati", "Bihar": "Patna",
                "Maharashtra": "Mumbai", "Rajasthan": "Jaipur"}

Statement-by-statement dry run

#StatementOutputWhy
aprint(stateCapital.get("Bihar"))Patnaget() looks the key up and returns its value
bprint(stateCapital.keys())dict_keys(['Assam', 'Bihar', 'Maharashtra', 'Rajasthan'])a view of all keys, in insertion order
cprint(stateCapital.values())dict_values(['Guwahati', 'Patna', 'Mumbai', 'Jaipur'])a view of all values
dprint(stateCapital.items())dict_items([('Assam', 'Guwahati'), ('Bihar', 'Patna'), ('Maharashtra', 'Mumbai'), ('Rajasthan', 'Jaipur')])a view of (key, value) tuples
eprint(len(stateCapital))4len() counts key-value pairs, not individual strings
fprint("Maharashtra" in stateCapital)Truein on a dict tests membership among the keys
gprint(stateCapital.get("Assam"))Guwahatisame key lookup as (a)
hdel stateCapital["Assam"] then print(stateCapital){'Bihar': 'Patna', 'Maharashtra': 'Mumbai', 'Rajasthan': 'Jaipur'}del removes the Assam pair; the remaining 3 pairs print in order

Full expected output

Patna
dict_keys(['Assam', 'Bihar', 'Maharashtra', 'Rajasthan'])
dict_values(['Guwahati', 'Patna', 'Mumbai', 'Jaipur']) …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.