import string searchstring = "1989" limit = 5 def main(): # Reads file top250.txt and prints the lop limit movies in the top 250 ranking # for the year specified in searchstring infile = open("top250.txt") infile.readline() infile.readline() infile.readline() total = 0 print "Top", limit, "movies of", searchstring for line in infile: if total < limit: fields = line.split(" ") length = len(fields) lastField = fields[length-1] year = lastField[1:5] if year == searchstring: total = total + 1 print fields main()