Search code examples
pythonlistnumbersunique

How do I find the uniqueness of the repetition of numbers?


An array of integers is given. Write a function that returns true, when each value inthe array occurs unique times. Example 1: 1)Input: array = [1,2,2,1,1,3] 2)Output: true Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values havethe same number of occurrences.

how do i solve? Please,help.


Solution

  • array =  [1,2,2,1,1,3]
    
    exm = {}
    for x in array:
        exm.setdefault(x, 0)
        exm[x] += 1
    
    if len(set(exm.values())) == len(set(array)):
        print("True")
    else:
        print("False")