counts = {} names_list = ['John', 'Anne', 'Sam', 'Li', 'Sam', 'John'] for name in names_list: counts[name] = counts.get(name,0) +1 print(counts)