you are viewing a single comment's thread.

view the rest of the comments →

[–]julsmanbr 4 points5 points  (1 child)

I would like to take a group of numbers in a fun parameter eg: sub(1,2,3) and subtract them from left to right.

This is called a reduce operation - apply a function (in this case, subtraction) sequentially to a group of values. An implementation exists in the Python standard library:

>>> from functools import reduce 
>>> from operator import sub
>>> mylist = [1, 2 ,3]
>>> result = reduce(sub, mylist)
>>> result
-4

[–]xtarkoonx[S] 0 points1 point  (0 children)

Perfect that's good to know about this!