Question: I have done splitting on the csv file(link given below) and my data output is given below. I need little help in comparing **country** column and return only the movie names that are made in the USA only. How do I do that?

```
data = open("movie_metadata.csv", "r").read().split("\\n")
movie_data = [i.split(",") for i in data]
print(movie_data[1:4])

output:
[['movie_title','director_name','color','duration','actor_1_name','language',
  'country','title_year'],
['Avatar','James Cameron','Color','178','CCH Pounder','English','USA',
 '2009'],
["Pirates of the Caribbean: At World's End",'Gore Verbinski','Color',
 '169','Johnny Depp','English','USA','2007'],
['Spectre','Sam Mendes','Color','148','Christoph Waltz','English','UK',
 '2015']]

```

[CSV File](http://www.sharecsv.com/s/dcb38ee98d6116ea5e9b3cdea3572115/Movie_metadata.csv)

Answer: 
You want to filter the list based on the country column. 

```
us_movies = [movie for movie in movies if movie[6] == 'USA'] 

```

You can also transform the line into just the title if you like.

```
us_movie_titles = [movie[0] for movie in movies if movie[6] == 'USA']

```

If you want a corresponding list of match predicate results, this will work:

```
is_match = [movie[6] == 'USA' for movie in movies]

```

Note, the size of the first two lists may be smaller than the original list, but is\_match will have the same size and ordering as your original list.

To add the booleans to your full dataset:

```
movies_with_usa = [m[0] + [m[1]] for m in zip(movies, is_match)]

```

But what you really have is named data, so it's probably more appropriate in a dictionary or object. Also, if you're reading a csv file, a csv reader is part of the standard library. So for something a little more robust

```
import csv

def read_data(filename):
    with open(filename) as f:
        reader = csv.DictReader(f)
        return [row for row in reader]     

def match(record, field, value):
    return record[field] == value

data = read_data("movie_metadata.csv")
us_movies = [record for record in data if match(record, 'country', 'USA')]      

```
Just iterate over all movies and compare the 7th column:

```
 made_usa = []   

 for l in movie_data:
        if l[6] == 'USA':
          made_usa.append(l)

 print (made_usa)

```

To add only the movie name, it is just to do this:

```
     made_usa = []   

     for l in movie_data:
            if l[6] == 'USA':
              made_usa.append(l[0])

      print (made_usa)

```

To save if there is a match or not, you can use a dictionary like this:

```
     made_usa = {}

     for l in movie_data:
            if l[6] == 'USA':
              made_usa.update({l[0]: 'True'})
            else:
              made_usa.update({l[0]: 'False'}) 
     print (made_usa)

```

After that, if you want to look if a certain move was made in USA or not. All you need to do is, for example:

```
print(made_usa['Avatar'])

```

Output:

```
'True'

```