aboutsummaryrefslogtreecommitdiff
path: root/challenge-263/luca-ferrari/python/ch-2.py
diff options
context:
space:
mode:
authorLuca Ferrari <fluca1978@gmail.com>2024-04-04 13:03:27 +0200
committerLuca Ferrari <fluca1978@gmail.com>2024-04-04 15:05:03 +0200
commit44a92ee6dd0ca577889cc1489e1237d5084a1efc (patch)
tree49d7ea43e0763e88f5812ddb0932336209f02b97 /challenge-263/luca-ferrari/python/ch-2.py
parentc2aa18d20881e4079d3858c0218ff99a07032d33 (diff)
downloadperlweeklychallenge-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/ch-2.py')
-rw-r--r--challenge-263/luca-ferrari/python/ch-2.py32
1 files changed, 32 insertions, 0 deletions
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: ] ) )