aboutsummaryrefslogtreecommitdiff
path: root/challenge-337/sgreen/python/ch-1.py
blob: 565e8bfd0095b26057853faff0ef0ae2f7e06630 (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
#!/usr/bin/env python3

import sys


def smaller_than_current(numbers: list) -> list:
    """For each number in the list, count how many numbers are smaller than it.

    Args:
        numbers: List of numbers.

    Returns:
        A list of counts, where each count corresponds to how many numbers in the
        input list are smaller than or equal to the number at that index.
    """
    solution = []

    for number in numbers:
        # Count how many numbers are smaller or equal than the current number.
        # Subtract one to exclude the current number itself.
        solution.append(sum(1 for n in numbers if n <= number) - 1)

    return solution


def main():
    # Convert input into numbers
    array = [float(n) for n in sys.argv[1:]]
    result = smaller_than_current(array)
    print(result)


if __name__ == '__main__':
    main()