Pyplot sorting y-values automatically

From matplotlib 2.1 on you can plot categorical variables. This allows to plot plt.bar([“apple”,”cherry”,”banana”], [1,2,3]). However in matplotlib 2.1 the output will be sorted by category, hence alphabetically. This was considered as bug and is changed in matplotlib 2.2 (see this PR). In matplotlib 2.2 the bar plot would hence preserve the order. In matplotlib … Read more

Counting Letter Frequency in a String (Python) [duplicate]

from collections import Counter counts=Counter(word) # Counter({‘l’: 2, ‘H’: 1, ‘e’: 1, ‘o’: 1}) for i in word: print(i,counts[i]) Try using Counter, which will create a dictionary that contains the frequencies of all items in a collection. Otherwise, you could do a condition on your current code to print only if word.count(Alphabet[i]) is greater than … Read more