Write a program extract least frequency element


Topic: Write a program extract least frequency element

Solution

from collections import defaultdict 
test_list = [1, 3, 4, 5, 1, 3, 5] 
  
print("The original list : " + str(test_list)) 
  
res = defaultdict(int) 
for ele in test_list: 
   res[ele] += 1 
min_occ = 9999
for ele in res: 
    if min_occ > res[ele]: 
        min_occ = res[ele] 
        tar_ele = ele 
  
print("The minimum occurring element is : " + str(tar_ele)) 



List all Python Programs