Sunday, 23 January 2022

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

Slip 12 Q 2

CODE :

Sample string: 'thequickbrownfoxjumpsoverthelazydog'
 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]))

OUTPUT:



No comments:

Post a Comment

Write a Java program to display given extension files from a specific directory on server machine.

 DOWNLOAD     SLIP14Q2 /** * STEPS TO RUN CODE * Step 01 compile the code * Step 02 run the code * Step 03 give a file directory locatio...