I was writing a program to count the frequency of alphabets based on the user input until "!" was introduced. The following is my program:
list1=[]
character = ""
while character != '!' :
character = input()
list1.append(character)
result=[]
for alphabet in ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] :
if list1.count(alphabet) > 0:
result.append(alphabet)
result.append(list1.count(alphabet))
print(result)
However, apparently, I should have counted the frequency until a new character has been plugged in the input. For instance, if the input is (aabc), then my program should count the two 'a's then move on to 'b'.
Is there anyway for me to modify my loop to count the frequency before moving on to a new alphabet?
I've used a dictionary
dwill contain the result after execution.