1. Welcome to the case study!
It's now time to flex those muscles and see what metal you're made of! In this chapter, you'll use your recently-gained skills of writing user-defined functions, iterators, list comprehensions and generators to wrangle and extract meaningful information from a real-world dataset,
2. World bank data
the World Bank World Development Indicators dataset. This dataset contains data on 217 world economies for over half a century, from 1960 up until 2015. The data contains hundreds of indicators from population, electricity consumption and CO2 emissions to literacy rates, unemployment and mortality rates. In the following few exercises, you'll use dictionaries, zipping, user-defined functions, and list comprehensions to wrangle some of this wonderfully rich dataset. Let's quickly recap these tools:
3. Using zip()
The zip function accepts an arbitrary number of iterables and returns an iterator of tuples. We bring back our two lists from before, one of the avengers, the other of their names. Passing these to the zip function creates a zip object which is an iterator of tuples. We can turn them into a list and then print this list.
4. Defining a function
For writing functions, function headers begin with the keyword def, followed by the function name, arguments inside parentheses and a colon. We then have the function body, with the docstrings enclosed in triple quotation marks; the rest of the function body performs the computation that the function does and closes with the keyword return, followed by the value or values to return.
5. Re-cap: list comprehensions
Comprehensions, in their most basic forms, are enclosed in square brackets and are structured as output expression for iterator variable in iterable. More advanced comprehensions can include conditionals on the output expression and/or conditionals on the iterable.
6. Let's practice!
Now that we've recapped all the tools that you'll need to hack away at this dataset in the next few exercises, let's get hacking! -