aboutsummaryrefslogtreecommitdiff
path: root/challenge-263/luca-ferrari/python/ch-2.py
diff options
context:
space:
mode:
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: ] ) )