Python | Checking the Similarity of List Items

Below are several ways to solve the problem. 
Method # 1 Using Collections. Counter

# Python3 demo code
# check if there is a list
# K percent are the same or not

from collections import Counter

  
# initializing list

ini_list1 = [ 1 , 2 , 3 , 1 , 1 , 1 , 1 , 1 , 3 , 2 ]

 
# print initial list

print ( "Initial list" , ini_list1)

 
# initialization K

K = 60

 
# code to check if the K% list is the same or not

i, freq = Counter (ini_list1) .most_common ( 1 ) [ 0 ]

 

if len (ini_list1) * (K / 100 ) & lt; = freq:

  print ( "True" )

else :

print ( "False" )

Exit:

 Initial list [1, 2, 3, 1 , 1, 1, 1, 1, 3, 2 ] True 

Method # 2: Using a Dictionary and Its Values ​​

Exit:

 initial list [1, 2, 3, 1, 1, 1, 1, 1 , 1, 1] True 

# Python3 demo code
# check if there is a list
# K percent are the same or not

from collections import Counter, defaultdict

 
# initializing list

ini_list1 = [ 1 , 2 , 3 , 1 , 1 , 1 , 1 , 1 , 3 , 2 ]

 
# print starting list

print ( "Initial list" , ini_list1)

 
# initializing K

K = 60

  
# code to check if the K% list is the same or not

freq = defaultdict ( int )

for x in ini_list1:

freq [x] + = 1

freq = freq.values ​​()

if max (freq) & gt; = (K / 100 ) * sum (freq):

  print ( "True" )

else :

  print ( "False" )