Skip to content
SamplePreview build: teacher profiles, ratings, reviews and lesson counts are sample data.
All tutors

Python Data Structures for Data Work

Choose between lists, dicts, sets and tuples with confidence and shape records the way data work needs.

By Efua Mensah Beginner Python for AI 4.7(3) 68 lessons taught Sample

Your first 3 replies from the tutor are free. Then you can continue the lesson for $4 from your credit.

A taste of a lesson

One question and the answer, as this tutor gives it.

Python Data Structures for Data Work AI tutor following Efua Mensah's plan
Student:

I have a list of orders as dicts. How do I get total spend per customer?

Tutor:

Group and add as you go. Use a dict where the key is the customer and the value is a running total. With defaultdict you can skip the is this key new check: totals = defaultdict(float), then for o in orders: totals[o['customer']] += o['amount']. Each order adds its amount to that customer's total. If some orders might lack an amount, use o.get('amount', 0) instead. Quick check: what would totals contain after two orders from the same customer worth 10 and 15?

Written by the teacher as an example. In your lesson the tutor answers your own questions, and like any AI it can be wrong.

What you will be able to do

  • Pick the right container for a data task and explain why
  • Count, group and deduplicate records with dicts, sets and collections helpers
  • Reshape data between rows (list of dicts) and columns (dict of lists)
  • Navigate nested JSON safely with defaults and type checks
  • Avoid aliasing, mutable default and change while looping bugs

Lesson plan

6 lessons. Pick one to start there.

  1. 1 Lists and tuples for ordered data Use lists for changing sequences and tuples for fixed records. Start
  2. 2 Dicts for lookup and records Store and retrieve data by key, and represent one record as a dict. Start
  3. 3 Sets for uniqueness and comparison Deduplicate values and compare groups with set operations. Start
  4. 4 Counting and grouping Summarise records by category with Counter and defaultdict. Start
  5. 5 Rows, columns and nested JSON Reshape records and read nested structures without crashing on missing fields. Start
  6. 6 Bugs that come from references Recognise and fix aliasing, copying and mutable default argument bugs. Start

Try asking

Tap a question to start a lesson with it.

About this tutor

For beginners who know basic Python syntax but freeze when real data arrives as a list of records, nested JSON or a column of values to deduplicate. You learn the four core containers through data tasks: grouping, counting, looking things up, removing duplicates and reshaping between a list of dicts and a dict of lists. The tutor shows comprehensions, the collections helpers for counting and grouping, and the classic traps such as mutable default arguments and changing a list while looping over it. You finish ready to move on to pandas, knowing what it does for you underneath.

Reviews

4.7

3 ratingsSample

  • Hannah L.Sample

    Good pace, lots of predict then run exercises. The nested JSON part was the most useful for me. A little slow at the start if you already know lists well.

  • Mateo R.Sample

    Grouping with defaultdict finally made sense because the examples used my own sales export. The mutable default argument lesson explained a bug I had for weeks.

  • Kenji O.Sample

    I like that it showed the long loop first and then the short version. I can actually read my own code a week later now.

About the teacher

Efua Mensah

Python teacher for people starting AI work from zero, patient with setup, files and first scripts

9 tutors 4.5(20) 377 lessons taught Sample

I teach Python to people who want to build with AI but have never written much code, or who tried once and got stuck on setup. My background is in teaching adult evening coding classes and later writing data scripts for small research teams, so I know where beginners lose an afternoon: the wrong interpreter, a confusing traceback, a file...

See Efua's profile and tutors