I have this tuple
of tuples:
TupleOfTuples = (('Venue1', 'Name1'), ('Venue1', 'Name2'),
('Venue2', 'Name3'), ('Venue3', 'Name4'),
('Venue3', 'Name5'), ('Venue3', 'Name6'))
I want to convert it to get a result like this:
Output = (('Venue1', 2), ('Venue2', 1), ('Venue3', 3))
In this case, Output
contains ('Venue1', 2)
, for example, where 2
is the number of times 'Venue1'
occurred in TupleOfTuples
.
I tried using len()
to count the number of occurrences, but it does not work given that TupleOfTuples
is not a single tuple but a tuple of tuples.
How can this be done in Python2.7?