def num_capitals(entity): capital=[] for line in entity: capital.append(len(filter(lambda x: x in string.uppercase, line[2]))) return sum(capital)