counts = dict()
names = ['David', 'Daniel', 'Michelle', 'Daniel', 'Ben', 'Ben', 'Daniel']
for name in names:
if name not in names:
counts[name] = 1
else:
counts[name] = counts[name] 1
print(counts)
CodePudding user response:
small error, should be if name not in counts:
counts = dict() names = ['David', 'Daniel', 'Michelle', 'Daniel', 'Ben', 'Ben', 'Daniel'] for name in names: if name not in counts: counts[name] = 1 else: counts[name] = counts[name] 1