How to count number of occurrences of a chracter in a string (list)
<p>I'm trying to count the occurrence of each character for any given string input, the occurrences must be output in ascending order( includes numbers and exclamation marks)
  I have this for my code so far, i am aware of the Counter function, but it does not output the answer in the format I'd like it to, and I do not know how to format Counter. Instead I'm trying to find away to use the count() to count each character. I've also seen the dictionary function , but I'd be hoping that there is a easier way to do it with count() </p>

<pre><code>from collections import Counter

sentence=input("Enter a sentence b'y: ")
lowercase=sentence.lower()

list1=list(lowercase)
list1.sort()

length=len(list1)
list2=list1.count(list1)
print(list2)

p=Counter(list1)
print(p)
</code></pre>

<p>Just call <a href="https://docs.python.org/3/library/collections.html#collections.Counter.most_common" rel="nofollow"><code>.most_common</code></a> and reverse the output with <a href="https://docs.python.org/3/library/functions.html#reversed" rel="nofollow"><em>reversed</em></a> to get the output from least to most common:</p>

<pre><code>from collections import Counter

sentence= "foobar bar"
lowercase = sentence.lower()
for k, count in  reversed(Counter(lowercase).most_common()):
    print(k,count)
</code></pre>

python list count