blob: c4f62495865c5d4ff30576367a72eeb63b459b56 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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: ] ) )
|