I want to count the occurence of a string in a given list than print it in alphabetically order. For example. I love my mom and I love my dad. Result: and:1 dad:1 I:2 love:2 mom:1 my:2
I am trying with this code. from collections import Counter z = ['I', 'love', 'my', 'mom', 'and', 'I','love','my','dad'] Counter(z) Counter({'love': 2, 'I': 2, 'my': 2, 'and': 1, 'dad': 1, 'mo': 1})