Im trying to split a string of letters into a dictionary which automatically adds the value +1 for every letter present more than once.
The only problem is that my code adds the value +1 for every key…For example if i input: “aasf” the dict will be: a:2, s:2, f:2… Whats wrong??
word = raw_input("Write letters: ")
chars = {}
for c in word:
chars[c] = c.count(c)
if c in chars:
chars[c] += 1
print chars
you must use either
OR
but not both.