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
- Choose between tuples, sets and dictionaries
- Count and group data
- Write comprehensions
- Parse text data
- Use generators for large or endless data
Lessons
- 1
Tuples and sets
Fixed groups of values, returning several results, and sets that keep each value only once.
- 2
Dictionaries
Look values up by key, count things, and loop over keys and values together.
- 3
List comprehensions
Build a list from a loop in one line, filter it with if, and make dictionaries the same way.
- 4
Processing text data
Split lines and fields, convert them, and turn raw text into numbers you can work with.
- 5
Generators Intermediate
Produce values one at a time with yield, and work with endless sequences without running out of memory.
Module practice
- Count the different valuesEasy
- Values in both listsMedium
- Different pairs with a given sumHard
- A phone bookEasy
- Word frequencyMedium
- The three most common wordsHard
- Passing marksEasy
- List of squaresEasy
- Words and their lengthsMedium
- Flatten and filterHard
- Count words and lettersEasy
- A CSV reportMedium
- Reading a server logHard
- Even numbers from a generatorEasy
- Fibonacci from a generatorMedium
- Windows over a listHard