aboutsummaryrefslogtreecommitdiff
path: root/challenge-260/sgreen/python/ch-1.py
blob: 90ba9f5b09f402c5aabb96f238e42e4f5c4470ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3

from collections import defaultdict
import sys


def uniq_occurrences(ints: list) -> bool:
    """Check the frequency of integers are unique

    Args:
        ints (list): The integers

    Returns:
        bool: Whether the frequency of the list is unique
    """

    # Calculate the frequency of each integer
    freq = defaultdict(int)
    for i in ints:
        freq[i] += 1

    # Return if we have seen a frequency already
    seen = {}
    for i in freq.values():
        if i in seen:
            return False
        seen[i] = 1

    # We have a unique orrurrence list
    return True


def main():
    # Convert input into integers
    array = [int(n) for n in sys.argv[1:]]
    result = uniq_occurrences(array)
    print('1' if result else '0')


if __name__ == '__main__':
    main()