diff options
Diffstat (limited to 'challenge-322/sgreen/python/ch-2.py')
| -rwxr-xr-x | challenge-322/sgreen/python/ch-2.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-322/sgreen/python/ch-2.py b/challenge-322/sgreen/python/ch-2.py new file mode 100755 index 0000000000..152fcf9e6f --- /dev/null +++ b/challenge-322/sgreen/python/ch-2.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import sys + + +def rank_array(ints: list) -> list: + """Return an array of the ranks of each element in a list + + Args: + ints (list): The input list + + Returns: + list: The position (1-based) of each integer + """ + # Generate a list of the sorted unique values. + sorted_list = sorted(set(ints)) + + # Return the position (1-based) of the each value. + return [sorted_list.index(i)+1 for i in ints] + + +def main(): + # Convert input into integers + array = [int(n) for n in sys.argv[1:]] + result = rank_array(array) + print(result) + + +if __name__ == '__main__': + main() |
