diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-05-13 00:29:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-13 00:29:17 +0100 |
| commit | 6bb7b79de03a9327f2850fdbb4298e08b3bef0bc (patch) | |
| tree | 9b4ef68693be95141f96d0fd5313dbcc8734eb61 /challenge-268/sgreen/python/ch-2.py | |
| parent | c5fcf2a0860873e8486191af5fa2c9ef8a39001c (diff) | |
| parent | 9c4b1bbba36ae9f46e2d8d6d1d4cef3e21572e87 (diff) | |
| download | perlweeklychallenge-club-6bb7b79de03a9327f2850fdbb4298e08b3bef0bc.tar.gz perlweeklychallenge-club-6bb7b79de03a9327f2850fdbb4298e08b3bef0bc.tar.bz2 perlweeklychallenge-club-6bb7b79de03a9327f2850fdbb4298e08b3bef0bc.zip | |
Merge pull request #10077 from simongreen-net/master
sgreen solutions to challenge 268
Diffstat (limited to 'challenge-268/sgreen/python/ch-2.py')
| -rwxr-xr-x | challenge-268/sgreen/python/ch-2.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-268/sgreen/python/ch-2.py b/challenge-268/sgreen/python/ch-2.py new file mode 100755 index 0000000000..d0abc6522c --- /dev/null +++ b/challenge-268/sgreen/python/ch-2.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +import sys + + +def numbers_game(ints: list) -> list: + # Check we have an even number of items + if len(ints) % 2 != 0: + raise ValueError('Please provide an even number of items!') + + # Sort the list + ints = sorted(ints) + + for i in range(0, len(ints), 2): + # Switch the pairs of numbers around + ints[i], ints[i+1], = ints[i+1], ints[i] + + return ints + + +def main(): + # Convert input into integers + array = [int(n) for n in sys.argv[1:]] + result = numbers_game(array) + print(tuple(result)) + + +if __name__ == '__main__': + main() |
