def vote(voter): box = dict.fromkeys([item[0] for item in voter], 0) for item in voter: box[item[0]] += 1 return box if __name__ == '__main__': voter = [ ['a', 'b'], ['a'], ['b'], ['a'], ['b'], ['c'], ] box = vote(voter) print(box)