ecs10-10-31

ecs10-10-31 - New Assignment ECS 10 10/31 Two Two weeks...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: New Assignment ECS 10 10/31 Two Two weeks long Hand Hand in preliminary version Nov. 5, complete version Nov. 12. You may work in teams of two. Both hand in same program. If If working in pairs, get together and work together, maybe in lab hours. Make sure you both understand and contribute to program. Basis Basis of second midterm. Foreclosure Foreclosure Map Many Eyes Many Eyes Foreclosure Data Only some counties are included in this thi table (Bay Area, SoCal, Coast, Central Valley). 1 What Does it Mean? Los Los Angeles county has the most foreclosures. Does Does this mean that the problem is worst in LA? Need to compare with population. There There are 9.5 million people in LA county, way more than any other in the state. Census Census Data Foreclosure Rate Foreclosures per 1000 people. Foreclosures Foreclosures * 1000 / population Compute Compute this ratio for every county Display Display using Many Eyes US Counties visualization. Overall Overall Project Plan Read Read census data. Build a data structure that lets us look up the population of a county. Read Read the foreclosure data. For each county: Look up its population in data structure Compute Compute ratio Write Write out line of table for Many Eyes Upload Upload completed table to Many Eyes and view visualization. Structure Structure of program Very Very typical program structure: while loop to read file put some data into a data structure loop to do something with data remove data from data structure produce some output Data Structure We We need to look up population by county name. Last Last time, we looked up Representative name by Congressional District. by This This won’t work for the new program. 2 Different Query Ask Ask for a name, report the district. Enter a Representative: Thompson Mike Thompson is the Representative from District 1 Th How How would you answer this? Efficient Efficient Solution With With list, have to read through whole list to find the name you’re looking for. Better Better to "look up" names, like in a phone book. book Use dictionary. Use a dictionary. A dictionary can be accessed by indexing, like dictionary a list, but any kind of data can be used as the index – not just the position! Dictionary Words Words are keys keys. Definitions Definitions are values are values. Dictionary Dictionary Entry myDict = {"ferret":"Ferdinand"} key value Curly Curly braces {} indicate a dictionary {} {} is the empty dictionary. Looking up an Item Look Look up a value, use key as index. name = myDict["ferret"] myDict["ferret"] value key Structure of Program Part Part 1: Reads in data, builds dictionary. Usually Usually has to read whole file. Can be very slow, but only done once. Part Part 2: gets and answers queries Use Use square brackets for indexing, just like a list. Goes Goes right to the data it needs. Does Does NOT have to look at all the data to answer the query. This This is very important for huge data, eg. Google, eg. airline reservations, myUCDavis. myUCDavis. 3 Using a Dictionary Initialize Initialize the empty dictionary: dataBase = {} Add Add values, use key as "index" dataBase[name] dataBase[name] = district Look Look up values using key as "index" district = dataBase[name] dataBase[name] Test Test if key is used in dictionary name in dataBase Look up in Dictionary Query Query asks for keys Returns Returns data items Check Check first to make sure key is in dictionary, otherwise it will crash your program! ll 4 ...
View Full Document

This note was uploaded on 03/23/2011 for the course ECS 10 taught by Professor Amenta during the Winter '07 term at UC Davis.

Ask a homework question - tutors are online