Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cs190c:lab3_09 [2009/01/30 12:02]
tang editing spec
cs190c:lab3_09 [2009/02/05 02:34] (current)
Line 97: Line 97:
 Tom Hanks was nominated for an Oscar in 2000 for Cast Away as Chuck Noland</​code>​ Tom Hanks was nominated for an Oscar in 2000 for Cast Away as Chuck Noland</​code>​
   - 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 =====
 +<code python>​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()</​code>​
 
cs190c/lab3_09.txt ยท Last modified: 2009/02/05 02:34 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki