You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
541 B
22 lines
541 B
def letter_counter(input):
|
|
counts = {}
|
|
for char in input:
|
|
if char in counts:
|
|
# If the key already exists, we just add to the existing count
|
|
counts[char] += 1
|
|
else:
|
|
# If we don't find the key, we'll add it and assign a count of 1
|
|
counts[char] = 1
|
|
|
|
# Remember to return OUTSIDE the for loop!
|
|
return counts
|
|
|
|
|
|
|
|
|
|
# Uncomment the code below if you want to test out the example code
|
|
|
|
# word_to_count = "banana"
|
|
# result = letter_counter(word_to_count)
|
|
# print(result)
|