Python: the basics

First steps with data: filtering, aggregating, debugging

In this chapter, you will learn to

Tools: Python

9 exercises

Each exercise is graded automatically, in your browser. The full statements are available once you have an account.

  1. What this is for in real life

    Before doing AI, you need to make a list of data talk, and Python is the common language of almost every AI tool. - Newsrooms. An online newspaper logs every article read. Finding out which sections really hold…

  2. Monday's chart

    You have just joined the newsroom of an online newspaper. On Monday morning, the editorial meeting always starts with the same question: how did last week go? The editor-in-chief would like to see it at a glance…

  3. The checkerboard

    The newspaper's games page publishes a draughts puzzle every week, and it needs a blank board of any size. Write draw_board(n), which prints a grid of n rows and n columns. Black squares are #, white squares are…

  4. Lesson: types in Python

    Why care. In data analysis, the same piece of information sometimes arrives as a number, sometimes as text. Mixing them up produces silent bugs: "12" + "3" equals "123", not 15. The four ubiquitous types -…

  5. Lesson: sorting in Python

    Sorting means ordering a list according to a criterion (a ranking, a top-N). Python offers two tools that must not be confused: - sorted(liste) returns a new sorted list, without touching the original. -…

  6. Front page

    You have just joined the newsroom of an online newspaper. Its homepage only has room for a handful of articles, and you are the one choosing them: you start with those readers actually opened. Your task. Write…

  7. Monthly review

    The month is drawing to a close, and the newsroom you work for is already preparing the next one. Which sections should it focus its efforts on: investigations? sports? culture? The editor-in-chief asks for your…

  8. The intern's code

    An intern at the newsroom wrote two functions to track readership: for each section, we want its average number of views over the past weeks. His code doesn't work. - make_grid(n_topics, n_weeks) must return a…

  9. The intern returns

    The intern is back, this time with 4 functions for going through the connection logs of the newspaper's website: - count_logins(logs): counts the number of appearances of each user. Returns a dict user → count.…