How to use counter to get the N least most common letters from a string in Python

1 Answer

0 votes
from collections import Counter

counter = Counter()
for ch in "python java":
    counter[ch] += 1

n = 3
lst = counter.most_common()[:-n-1:-1] 

print(lst)



'''
run:

[('r', 1), (' ', 1), ('n', 1)]
 
'''

 



answered Jul 26, 2019 by avibootz

Related questions

...