lec-11-13

lec-11-13 - 11/13/2009 1 ECS 10 11/13 Announcements MIDTERM...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: 11/13/2009 1 ECS 10 11/13 Announcements MIDTERM 2 -- Mon Nov 16 Open book, open notes. Bring sample programs from class, your programs, the book, etc etc. Bring a Scantron 2000 On myUCDavis: sample midterm. Topics Lists, indexing, concatenation of lists range and len functions for loops on lists and strings for loops on dictionaries and files for loops on dictionaries and files Files String methods (split, replace, strip, find) Dictionaries Exceptions sort method on lists Programming problem We will construct a program that reads in a file containing one country per line, and, for each country, a list of major exports. The program should reverse this output: it should output a file containing one export per line, and with each export, a list of countries. Solve this problem using a dictionary, in which the keys are the exports and the values are lists of countries. Programming problem Sample input: Albania, textiles, metals, oil Algeria, oil, natural gas Argentina edible oils oil grain motor vehicles Argentina, edible oils, oil, grain, motor vehicles Sample output: oil: Albania, Algeria, Argentina metals: Albania textiles: Albania edible oils: Argentina How to approach this problem? What are the entries in the dictionary? How do they get put in? Write this part first; most likely from reading a file. For each line of the file what goes into the For each line of the file, what goes into the dictionary? How do they get taken out? Querys from user for loop on dictionary 11/13/2009 2 List indexing example import random suits = ['Hearts', 'Clubs', 'Spades', 'Diamonds'] faces = ['J', 'Q', 'K'] i = random.randrange(4) num = random.randrange(13) if num < 10: print 'My card is the',num+1,'of',suits[i] else: print 'My card is the',faces[num-11],'of',suits[i] Example MC question The program: dogList = [Collie, Beagle,\...
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.

Page1 / 5

lec-11-13 - 11/13/2009 1 ECS 10 11/13 Announcements MIDTERM...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online