Q:

Write a Python program to count repeated characters in a string

0

Write a Python program to count repeated characters in a string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import collections
str1 = 'thequickbrownfoxjumpsoverthelazydog'
d = collections.defaultdict(int)
for c in str1:
    d[c] += 1

for c in sorted(d, key=d.get, reverse=True):
  if d[c] > 1:
      print('%s %d' % (c, d[c]))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now