From 44a92ee6dd0ca577889cc1489e1237d5084a1efc Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Thu, 4 Apr 2024 13:03:27 +0200 Subject: 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 --- challenge-263/luca-ferrari/python/ch-1.py | 23 ++++++++++++++++++++++ challenge-263/luca-ferrari/python/ch-2.py | 32 +++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 challenge-263/luca-ferrari/python/ch-1.py create mode 100644 challenge-263/luca-ferrari/python/ch-2.py (limited to 'challenge-263/luca-ferrari/python') 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 +# + +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 +# + +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: ] ) ) -- cgit