Skip to content
Exercise · Q6

Q.When to use tuple or dictionary in Python. Give some examples of programming situations mentioning their usefulness.

Uttarakhand UbseTextbookSubjective· 3mImportance★★★★★est
93% · 28/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 →

Tuple = a fixed record whose positions carry meaning (DOB, coordinates, RGB, function returns, dict keys); dictionary = a lookup table whose keys carry meaning (phone book, marks by roll number, state → capital).

The choice follows from how the data is identified and whether it changes:

When to use a TUPLE — fixed, position-meaningful, unchanging data

  1. Fixed records: a date of birth (17, 4, 2008), a coordinate (28.61, 77.20), an RGB colour (255, 0, 128). Position 0 means day/latitude/red — and the record must never be edited accidentally. Immutability enforces that.
  2. Multiple values returned by a function: return total, diff arrives as a tuple — natural and safe.
  3. Dictionary keys: only immutable objects can key a dict, so composite keys must be tuples:
distance = {("Delhi", "Mumbai"): 1400, ("Delhi", "Kolkata"): 1500}
print(distance[("Delhi", "Kolkata")])
1500

When to use a DICTIONARY — data retrieved by a meaningful key

  1. Phone book / contact list: name → number; you look up "Amit", never "entry number 7".
  2. Student marks by roll number: {23: 87, 24: 92} — direct access marks[24] without searching.
  3. Real-world mappings: state → capital, word → meaning, username → profile.
  4. Frequency counting: tally words/characters as counts[word] += 1 — the classic dictionary pattern.
stateCapital = {"Bihar": "Patna", "Rajasthan": "Jaipur"}
stateCapital["Kerala"] = "Thiruvananthapuram"   # grows as data arrives
print(stateCapital["Kerala"])
Thiruvananthapuram
``` …

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.