First time here can anyone tell me how to put this loop in a dict comprehension?
counts = {}
for word in words:
if word in counts:
counts[word] = counts[word] + 1
else:
counts[word] = 1
print(counts)
First time here can anyone tell me how to put this loop in a dict comprehension?
counts = {}
for word in words:
if word in counts:
counts[word] = counts[word] + 1
else:
counts[word] = 1
print(counts)