Mar-06-2019, 09:24 PM
(This post was last modified: Mar-06-2019, 09:24 PM by TreasureDragon.)
This is what I have so far and it is able to print out how many times a letter was printed but in order which it shows up in the string. I want it to first categorize by the number of times it popped up like the example output: (Also mine counts spaces, punctuations, etc. too but I don't want that)
This is what I have:
Sentence Statistics : e appeared 3 times . a appeared 2 times . g appeared 2 times . l appeared 2 times . o appeared 2 times . c appeared 1 times . d appeared 1 times . i appeared 1 times . m appeared 1 times . n appeared 1 times . t appeared 1 times . w appeared 1 times .Yes with the space between >1 and 1.
This is what I have:
string = input("Enter a Sentence: ") print(f"\nSentence Statistics:") one = 0 from collections import Counter count = Counter(string) for i in string: if count[i] == 1 and one == 0: print(f"\n{i} appeared {count[i]} times.") one += 1 elif count[i] == 1 and one >= 1: print(f"{i} appeared {count[i]} times.") if count[i] > 1: print(f"{i} appeared {count[i]} times.")