Computer Science, asked by nalinidebata, 9 months ago

Program to find frequencies of all elements of a list. Also, print the list of unique elements in the list
and duplicate elements in the given list. solve this problem in python.​

Answers

Answered by Anonymous
10

The idea is to use list method count() to count number of occurrences. Counter method returns a dictionary with occurrences of all elements as a key-value pair, where key is the element and value is the number of times that element has occurred.

Answered by mindfulmaisel
6

frequencies of all elements of a list

Explanation:

array = [1,2,3,1,2,5,6,13,12,12,99,9,4,4,7,100]

print("Given Array:",*array)

d = {}

for i in array:

   if i not in d:

       d[i]=1

   else:

       d[i]+=1

print("\nFrequency of each number: ")

for i in d:

   print("{}:{} ".format(i, d[i]), end=" ")

print("\nUnique Numbers: ")

for i in d:

   if d[i]==1:

       print("{}".format(i), end = " ")

print("\nDuplicate Numbers: ")

for i in d:

   if d[i]!=1:

       print(i, end=" ")

print()

hence, this is the required program to find frequencies of all elements of a list. Also, print the list of unique elements in the list

and duplicate elements in the given list.

Similar questions