IMDB file reading

posted by: Ms. Martin 24 May 2010 No Comment

Write a program that reads from the file imdb.txt and searches it for a keyword. The file is organized in the following way:

rank rating votes title (year)

You should ask the user what to search for then display ALL titles that contain that text. Here is a sample run (user input is underlined):

Search word? american
American Beauty (1999) is ranked 35 with a rating of 8.5
American History X (1998) is ranked 41 with a rating of 8.5
American Gangster (2007) is ranked 94 with a rating of 8.2

You should exactly reproduce the format shown above.  In other words, your output should be as follows:
title (year) is ranked ranking with a rating of rating

Notice that the search is case insensitive. The trickiest part will be displaying the entire title. Here is one way to do it:
1. Split each line of input
2. You know that the title always starts at index 3 of the split line
3. Use the string join method. This joins the parts of a list together into a string separated by the string it’s called on.

Here is the code you need:
title = " ".join(tokens[3:])
What this does is squish together all parts of the title into one string separated by spaces.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>