Logo

Programming-Idioms

History of Idiom 195 > diff from v6 to v7

Edit summary for version 7 by strom-und-spiele:
New Python implementation by user [strom-und-spiele]

Version 6

2019-10-05, 22:04:51

Version 7

2020-10-23, 17:30:59

Idiom #195 Pass a two-dimensional array

Pass an array a of real numbers to the procedure (resp. function) foo. Output the size of the array, and the sum of all its elements when each element is multiplied with the array indices i and j (assuming they start from one).

Idiom #195 Pass a two-dimensional array

Pass an array a of real numbers to the procedure (resp. function) foo. Output the size of the array, and the sum of all its elements when each element is multiplied with the array indices i and j (assuming they start from one).

Variables
a,foo,i,j
Code
def foo(a):
    print(len(a))
    print(sum(
        x*(i+1) + y*(i+1)*2 for i, (x, y) in enumerate(a)
    ))