diff options
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: ] ) ) |
