15,174,684 members
See more:
I want to create a program that can print the number of movies that was watched by more than 3 people(data stored in a nested list as below ).

list_movies = [('Spiderman 3', ['John', 'jake','Ronald']),('Gravity',['james','jake','john','gerald']),
('Terminator',['Anne','Johnny','Peter','Ronald','Neville'])]

What I have tried:

Python
```list_movies = [('Spiderman 3', ['John', 'jake','Ronald']),('Gravity',['james','jake','john','gerald']),
('Terminator',['Anne','Johnny','Peter','Ronald','Neville'])]

count2 = 0
for (movie,name) in list_movies:
count = 0
for (name) in list_movies:
if name != '':
count += 1
if count > 3:
count2 += 1

print(count)
print(count2)```
Posted
Updated 21-Oct-18 22:25pm

## Solution 1

You inner loop should iterate over the second item of the tuple:
Python
```list_movies = [('Spiderman 3', ['John', 'jake','Ronald']),('Gravity',['james','jake','john','gerald']),
('Terminator',['Anne','Johnny','Peter','Ronald','Neville'])]

count2 = 0
for (movie,viewers) in list_movies:
count = 0
for (name) in viewers:
if name != '':
count += 1
if count > 3:
count2 += 1

print("last movie viewers: %d" % count)
print("count of movies having had more than three viewers: %d" % count2)```
[no name] 22-Oct-18 3:42am

Is it a tuple or a nested list?
CPallini 22-Oct-18 4:02am

There is a list (the outer list) of tuples. Each tuple contains in turn a string (first item) and a list (the inner list) of strings (second item).