You are viewing a single comment's thread. Return to all comments →
Step 1: #importing collections packages to use its functions, specificaly Counter
from collections import Counter
Step 2: using sorted functions this will short the charecters alphabetically before even counting the frequency of each charecters
sort_s = sorted(s)
Step 3: using Counter function from collections package in python to count and pair each character with its frequency
character_counts = Counter(sort_s)
Step 5: printing key and value of dic in Counter but only top 3
for char, count in character_counts.most_common(3): print (char, count)
Seems like cookies are disabled on this browser, please enable them to open this website
Company Logo
You are viewing a single comment's thread. Return to all comments →
Step 1: #importing collections packages to use its functions, specificaly Counter
from collections import Counter
Step 2: using sorted functions this will short the charecters alphabetically before even counting the frequency of each charecters
sort_s = sorted(s)
Step 3: using Counter function from collections package in python to count and pair each character with its frequency
character_counts = Counter(sort_s)
Step 5: printing key and value of dic in Counter but only top 3