Slip 12 Q 2
CODE :
Sample string: 'thequickbrownfoxjumpsoverthelazydog'
Expected output: o-4, e-3, u-2, h-2, r-2, t-2
Expected output: o-4, e-3, u-2, h-2, r-2, t-2
import collections
str1 = input('Enter a string : ')
d = collections.defaultdict(int)
for c in str1:
if c ==' ':
continue
d[c] += 1
for c in sorted(d, key=d.get):
if d[c] > 1:
print('%s - %d' % (c, d[c]))
No comments:
Post a Comment