Working with data

Choosing the right collection, counting and grouping, turning raw text into data, and producing values only when needed.

About 9 hours of study

Learning objectives

Lessons

  1. 1

    Tuples and sets

    Fixed groups of values, returning several results, and sets that keep each value only once.

  2. 2

    Dictionaries

    Look values up by key, count things, and loop over keys and values together.

  3. 3

    List comprehensions

    Build a list from a loop in one line, filter it with if, and make dictionaries the same way.

  4. 4

    Processing text data

    Split lines and fields, convert them, and turn raw text into numbers you can work with.

  5. 5

    Generators Intermediate

    Produce values one at a time with yield, and work with endless sequences without running out of memory.

Module practice

Module quiz

1. Which collection answers "have I seen this before?" fastest?
2. What is {"a": 1}.get("b", 5)?
3. What is [x for x in range(5) if x % 2]?
4. Why might "a,b".split(",")[0] + 1 fail?
5. What is the main benefit of a generator over a list?
6. What is the type of {} in Python?

‹ Functions and modulesReliable code ›