Skip to content

HFP CH 5

Jacob Amey edited this page Aug 19, 2013 · 1 revision

Chapter 5 - Putting data in its place

(hashes and databases)

30 Pages Long

Description:

Chapter 5 covers the use of Hashes and Databases. This chapter was very straight forward and stayed true to covering hashes in details as well as a good intro to using databases.

The Code:

In this chapter you wright a new program that pules data from a database and displays Surfer information. You also Improve upon the High Score program form Chapter 4.

Main Concepts Covered:

  1. hash - a data structure that associates a name with a value.
  2. s['age'] - retrieve the value associated with the 'age' name in a hash called 's'.
  3. returning a data structure from a function.
  4. database system - a technology, like SQlite3, that can store large quantities of data in a very efficient way.

Python Tools Covered:

  • {} - an empty hash
  • s['wind'] = "off shore" - sets that value associated with "wind" in the "s" hash to the value "off shore"
  • s.keys() - provide a list of keys for the hash called 's'.
  • s.items() - provide a list of keys AND values for the hash called 's'.
  • line.split(",") - split the string contained within the 'line' variable at every occurrence of a comma.
  • sorted() - a built-in function that can sort most data structures.

Clone this wiki locally