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>Another way to avoid using Counter.</p>

<pre><code>sentence = 'abc 11 222 a AAnn zzz?? !'
list1 = list(sentence.lower())
#If you want to remove the spaces.
#list1 = list(sentence.replace(" ", ""))

#Removing duplicate characters from the string  
sentence = ''.join(set(list1))
dict = {}
for char in sentence:
    dict[char] = list1.count(char)

for item in sorted(dict.items(), key=lambda x: x[1]):
    print 'Number of Occurences of %s is %d.' % (item[0], item[1])
</code></pre>

<p>Output:</p>

<pre><code>Number of Occurences of c is 1.
Number of Occurences of b is 1.
Number of Occurences of ! is 1.
Number of Occurences of n is 2.
Number of Occurences of 1 is 2.
Number of Occurences of ? is 2.
Number of Occurences of 2 is 3.
Number of Occurences of z is 3.
Number of Occurences of a is 4.
Number of Occurences of   is 6.
</code></pre>

python list count