I am fairly new to python, but I haven't been able to find a solution to my problem anywhere.
I want to count the occurrences of a string inside a list of tuples.
Here is the list of tuples:
list1 = [
('12392', 'some string', 'some other string'),
('12392', 'some new string', 'some other string'),
('7862', None, 'some other string')
]
I've tried this but it just prints 0
for entry in list1:
print list1.count(entry[0])
As the same ID occurs twice in the list, this should return:
2
1
I also tried to increment a counter for each occurrence of the same ID but couldn't quite grasp how to write it.
*EDIT: Using Eumiro's awesome answer. I just realized that I didn't explain the whole problem. I actually need the total amount of entries which has a value more than 1. But if I try doing:
for name, value in list1:
if value > 1:
print value
I get this error:
ValueError: Too many values to unpack