Introducing Python

Python materials

Navigate your way on your awesome working machines (no setup today yay!) to the 2-Python-Challenge directory and type in ipython notebook.

Start a new notebook and we’ll go through the demo placed at this link:

http://nbviewer.ipython.org/urls/raw.github.com/adina/boot-camps/master/grannies.ipynb

Note do these all within one cell in the notebook. Bonus points if you can figure out why.

Exercise 1:

Make a dictionary of the data in the grannies.txt file.

Exercise 2:

For each key in the grade dictionary, print out the corresponding values in the grannies dictionary.

Exercise 3:

Edit the grades dictionary to include the values of the grannies dictionary.

Exercise 4:

I’m going to show you some code, work with your partner to figure out what will print based on that code.

Exercise 5:

Split and assign variables to the new grannies file containing both grades and deaths.

Hint: Dont do this on the giant file.

Exercise 6:

Look at the dict.get method for dictionaries.

I’m going to show you some code, work with your partner to figure out what is going on in this code.

Bonus: Try to automate this code from start to finish.

comments powered by Disqus

Table Of Contents

Previous topic

Testing

Next topic

Introducing SQL

This Page




Edit this document!

This file can be edited directly through the Web. Anyone can update and fix errors in this document with few clicks -- no downloads needed.

  1. Go to Introducing Python on GitHub.
  2. Edit files using GitHub's text editor in your web browser (see the 'Edit' tab on the top right of the file)
  3. Fill in the Commit message text box at the bottom of the page describing why you made the changes. Press the Propose file change button next to it when done.
  4. Then click Send a pull request.
  5. Your changes are now queued for review under the project's Pull requests tab on GitHub!

For an introduction to the documentation format please see the reST primer.