We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Collections
- Company Logo
- Discussions
Company Logo
Company Logo
Sort by
recency
|
1218 Discussions
|
Please Login in order to post a comment
from collections import Counter s = Counter(sorted(input(''))).most_common(3) for x in s: print(f'{x[0]} {x[1]}')
Solution without using collections
s=input() l1=[] l2=[] s=sorted((s)) c=0
for i in range(0,len(s)-1): if(s[i]!=s[i+1]): l1.append(s[i]) l2.append(c+1) c=0 else: c+=1 for i in range(0,len(l2)): for j in range(i+1,len(l2)): if(l2[i]