-1

i have a function "sas" which takes 12 arguments. i created a list with itertools product like this

p = Pool(processes=8)
nar = []
for i, t in itertools.product(range(50, 450, 50), range(50, 450, 50)):
    nar.append([300, 382, i, t, 86, 264, 418, 4, 5, 4, 5, 4])

this created a list of lists

i am trying to map a function over this list but it takes only 1 argument at a time , with error "missing 11 required positional arguments: "

i tried this

data = p.map(sas, nar)

and this

data = p.map(sas, [i for i in nar])

and some others i suspect even more stupid

how can i iterate over list of lists using list of 12 numbers at a time

kenan
  • 15
  • 6
  • 1
    Seems you're looking for `Pool().starmap(yourfunc, nar)`. – Darkonaut Jan 16 '20 at 00:47
  • this did work. great. can i accept a comment as answer? – kenan Jan 16 '20 at 01:18
  • ok, . i am new to python as you can probably see. i searched and saw that page amongst others . i could not fix with that. it seems the solution is to use starmap.. thanks , you were great help whether you like it or not . – kenan Jan 16 '20 at 10:36

1 Answers1

2

This should work:

data = [sas(*items) for items in nar]
Matt Shin
  • 424
  • 2
  • 7
  • i have to map calculations on processors, so i cannot escape from "p.map " – kenan Jan 16 '20 at 00:27
  • Does this work? `p.map(lambda items: sas(*items), nar)` – Matt Shin Jan 16 '20 at 00:41
  • did not work, "pickle.PicklingError: Can't pickle at 0x00000212584A0438>: attribute lookup on __main__ failed" – kenan Jan 16 '20 at 00:57
  • Sorry if it sounds silly, but can `sas` be modified to take a list as argument instead of taking 12 arguments? Your original logic will then work. Alteratively, write the lambda as a normal function and supply p.map with the name of the function. – Matt Shin Jan 16 '20 at 06:56