diff options
| author | Luca Ferrari <fluca1978@gmail.com> | 2024-04-04 13:03:27 +0200 |
|---|---|---|
| committer | Luca Ferrari <fluca1978@gmail.com> | 2024-04-04 15:05:03 +0200 |
| commit | 44a92ee6dd0ca577889cc1489e1237d5084a1efc (patch) | |
| tree | 49d7ea43e0763e88f5812ddb0932336209f02b97 /challenge-263/luca-ferrari/python | |
| parent | c2aa18d20881e4079d3858c0218ff99a07032d33 (diff) | |
| download | perlweeklychallenge-club-44a92ee6dd0ca577889cc1489e1237d5084a1efc.tar.gz perlweeklychallenge-club-44a92ee6dd0ca577889cc1489e1237d5084a1efc.tar.bz2 perlweeklychallenge-club-44a92ee6dd0ca577889cc1489e1237d5084a1efc.zip | |
PWC 263
Task 1 Raku done
Task 2 Raku done
Task 1 PL/Perl done
Task 2 PL/Perl done
Task 1 PL/PgSQL done
Task 2 PL/PgSQL done
Task 1 PL/Java done
Task 2 PL/Java done
Task 1 Python done
Task 2 PYthon done
Diffstat (limited to 'challenge-263/luca-ferrari/python')
| -rw-r--r-- | challenge-263/luca-ferrari/python/ch-1.py | 23 | ||||
| -rw-r--r-- | challenge-263/luca-ferrari/python/ch-2.py | 32 |
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge-263/luca-ferrari/python/ch-1.py b/challenge-263/luca-ferrari/python/ch-1.py new file mode 100644 index 0000000000..445b48b004 --- /dev/null +++ b/challenge-263/luca-ferrari/python/ch-1.py @@ -0,0 +1,23 @@ +#!python + +# +# Perl Weekly Challenge 263 +# Task 1 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-263> +# + +import sys + +# task implementation +# the return value will be printed +def task_1( args ): + k = int( args[ 0 ] ) + nums = list( map( int, args[ 1: ] ) ) + nums.sort() + return list( filter( lambda x: nums[ x ] == k, range( 0, len( nums ) ) ) ) + + +# invoke the main without the command itself +if __name__ == '__main__': + print( task_1( sys.argv[ 1: ] ) ) diff --git a/challenge-263/luca-ferrari/python/ch-2.py b/challenge-263/luca-ferrari/python/ch-2.py new file mode 100644 index 0000000000..c4f6249586 --- /dev/null +++ b/challenge-263/luca-ferrari/python/ch-2.py @@ -0,0 +1,32 @@ +#!python + +# +# Perl Weekly Challenge 263 +# Task 2 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-263> +# + +import sys + +# task implementation +# the return value will be printed +def task_2( args ): + quantity = {} + for index in range( 0, len( args ) - 1 ): + if index % 2 == 1: + continue + + item = args[ index ] + qty = int( args[ index + 1 ] ) + if item in quantity: + quantity[ item ] += qty + else: + quantity[ item ] = qty + + return quantity + + +# invoke the main without the command itself +if __name__ == '__main__': + print( task_2( sys.argv[ 1: ] ) ) |
