🚀 New batches open: Advanced Excel • Power BI • SQL • AI for Analytics — Book a free demo

Day 5 — Python dictionaries, tuples and sets

A list remembers order. A dictionary remembers labels — and that is what most real data needs.

Dictionaries — key and value

Adding and changing

Asking for a key that is not there is an error Use .get() when a key might be missing — it returns None, or whatever default you give it, instead of stopping your program.

Looping over a dictionary

keys, values, items

Tuples — a list that cannot change

That last line is unpacking, and it is everywhere in real Python.

Sets — unique values only

Which one do I use? List when order matters and repeats are fine. Dictionary when each value has a label. Tuple when the group should not change. Set when you only care about unique values.

Try these yourself

  1. Build a dictionary for one customer with name, city and amount, then print just the city.
  2. Use .get() to ask for a key that does not exist.
  3. Loop over a dictionary of three sales reps and print each name and total.
  4. Count the unique values in [1,2,2,3,3,3].

Ready for pandas and real projects?

This tutorial covers core Python. Our Data Analytics course takes you into pandas, NumPy, real files and visualisation, with mentor support and portfolio projects.

See the course →