diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-05-25 20:56:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-25 20:56:25 +0100 |
| commit | 2d8fc729ab08c9841689ac21c18ad555edd80013 (patch) | |
| tree | 340ba049aca84d8d4671642300f83699a385bb27 /challenge-322/sgreen/python/ch-2.py | |
| parent | 116589b5590d5ebb06fa5ad5a72b615ed43c5f9d (diff) | |
| parent | f8ffba5d2256ee11e2a9ff667cc042b12c4b307e (diff) | |
| download | perlweeklychallenge-club-2d8fc729ab08c9841689ac21c18ad555edd80013.tar.gz perlweeklychallenge-club-2d8fc729ab08c9841689ac21c18ad555edd80013.tar.bz2 perlweeklychallenge-club-2d8fc729ab08c9841689ac21c18ad555edd80013.zip | |
Merge pull request #12076 from simongreen-net/master
sgreen solutions to challenge 322
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() |
