For example, I am trying to count the amount of times a letter appears in my input. Also, I'm trying to use the tools I've learned so far. I haven't learned the .count tools in the course I'm taking so far.
1st I run this code:
any_word = input()
char_amount = {}
for i in any_word:
char_amount[i] = len(i)
print(char_amount)
My input is: hello
The result is this: I get every time is below and my if statements fail to update the key for 'l'
to 2
.
{'h': 1, 'e': 1, 'l': 1, 'o': 1}
My if statements fail to update the key for 'l'
to 2
. I cant figure out the logic to an if statement to add 1
to the 'l'
key because the duplicate is recognized in every key and the result is below. I assume i need another variable but i can't think up the logic. Thanks for any help:
{'h': 2, 'e': 2, 'l': 2, 'o': 2}