This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: controls! The map ± Yet another crazy aspect of our democracy. List of Lists ± When we dump our lists out of the dictionary they are in no particular order. ± Doesn’t matter for this project. ± But what if we want to print them out in some order? Imposing order ± How do we rank states by votes per million, or by population, or by alphabetical order? ± Put the data into a list, then use the sort() method. popList.sort() ± Rearranges the list! 11/6/2009 3 Organizing dictionary data ± Dump dictionary of lists into list of lists. ± Then sort that. ± List of lists: LoL = [ [2 3] [5 2] [1 6] [2 6] LoL = [ [2,3], [5,2], [1,6],[2,6] ] ± What is LoL ? Sorting by votes per million LoL= for state in popDict: dataList = popDict[state] pop = dataList votes = dataList ratio = (votes/pop)*1000000 LoL = LoL+[[ratio,state]] LoL.sort() for item in LoL: print item...
View Full Document
This note was uploaded on 01/14/2010 for the course ECS 10 taught by Professor Amenta during the Spring '07 term at UC Davis.
- Spring '07