Find the distinct values, frequency of values and all the elements that appear more than n/k times in a given list. (Using Python)




 '''
Following logics in single program.
Find the distinct values of array
Find the frequency of each number of array.
Find all the elements that appear more than n/k times. 
'''

#COUNT THE FREQUENCY OF EACH NUMBER OF LIST
A=[18, 15, 11, 10, 11, 12, 11, 20, 10, 10, 20, 15, 19, 20, 10]
X=[]
n=len(A)
for i in range(0,n):
     flag=0
     for j in range(0,len(X)):
          if A[i]==X[j]:
               flag+=1
     if flag==0:
          X.append(A[i])

#Printing Array Values
print("Values of List-A are:")
print(A)
#Printing the Distinct Values
print("Distinct Values of List-A are:")
print(X)
Freq=[]
     
for i in range(0,len(X)):
     flag=0
     for j in range(0,n):
          if X[i]==A[j]:
               flag+=1
     Freq.append(flag)     
#Printing Frequency of Array
print(Freq)
k=int(input('Enter K: '))
for i in range(0,len(Freq)):
     if Freq[i]>= n//k:
          print(X[i],"=",Freq[i],"appears times")





No comments

Post your comments

Powered by Blogger.