# Differences

This shows you the differences between two versions of the page.

 cs190c:lab3_09 [2009/01/30 12:02]tang editing spec cs190c:lab3_09 [2009/02/05 02:34] (current) Both sides previous revision Previous revision 2009/02/05 02:34 tang adding solution2009/01/30 12:02 tang editing spec2009/01/30 12:01 tang changing demo code2009/01/30 12:00 tang 2009/01/28 16:21 seh created Next revision Previous revision 2009/02/05 02:34 tang adding solution2009/01/30 12:02 tang editing spec2009/01/30 12:01 tang changing demo code2009/01/30 12:00 tang 2009/01/28 16:21 seh created Line 97: Line 97: Tom Hanks was nominated for an Oscar in 2000 for Cast Away as Chuck Noland​ Tom Hanks was nominated for an Oscar in 2000 for Cast Away as Chuck Noland​ - Lastly, since there is no reason why you need the entire list of Oscar nominees at once, you should process each line one at a time, rather than loading all of the entries before doing a search. - Lastly, since there is no reason why you need the entire list of Oscar nominees at once, you should process each line one at a time, rather than loading all of the entries before doing a search. + + ===== Solution ===== + ​def main(): + f = open('​actor2.txt',​ '​r'​) + prev_year = 0 + actor = raw_input('​Enter the actor: ') + for line in f: + nomination = line.split(','​) + nomination[0] = int(nomination[0]) + if nomination[1].lower() == actor.lower():​ + if prev_year != nomination[0]:​ + print nomination[1],​ 'won an Oscar in', nomination[0],​ '​for',​ nomination[2] + else: + print nomination[1],​ 'was nominated for an Oscar in', nomination[0],​ '​for',​ nomination[2] + if nomination[0] != prev_year: + prev_year = nomination[0] + + f.close() + main()

cs190c/lab3_09.txt ยท Last modified: 2009/02/05 02:34 (external edit)