Q:

Write a Python program to find the characters in a list of strings which occur more than and less than a given number.

0

Write a Python program to find the characters in a list of strings which occur more than and less than a given number.

All Answers

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

from collections import Counter 
from itertools import chain 
def max_aggregate(list_str, N):
    temp = (set(sub) for sub in list_str) 
    counts = Counter(chain.from_iterable(temp)) 
    gt_N =  [chr for chr, count in counts.items() if count > N]
    lt_N =  [chr for chr, count in counts.items() if count < N]
    return gt_N, lt_N
     
list_str = ['abcd', 'iabhef', 'dsalsdf', 'sdfsas', 'jlkdfgd'] 
print("Original list:")
print(list_str)
N = 3
result = max_aggregate(list_str, N)
print("\nCharacters of the said list of strings which occur more than:",N)
print(result[0])
print("\nCharacters of the said list of strings which occur less than:",N)
print(result[1])

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