Argument unpacking in function signatures has been removed in Python 3 (See this answer).
Here are some alternatives:
Solution 1:
If you want to get the same effect with clean code, @bereal's answer is a good choice:
[arr[i:j][k] for i, j, k in cmds]
This is a for loop / list comprehension, so unpacking is allowed.
Solution 2:
If you insist on using map
, you can do so with nested lambdas:
list(map(lambda cmd: (lambda i,j,k: arr[i:j][k])(*cmd), cmds))
In the outer lambda, cmd
is assigned an element in cmds
, which corresponds to a list of length 3. The return value of this outer lambda is an IIFE that defines an inner lambda taking 3 arguments, which we pass in by unpacking the cmd
argument from the outer lambda.
Solution 3:
This one's by @KellyBundy:
list(map(lambda i,j,k: arr[i:j][k], *zip(*cmds)))
In this case, this is equivalent to
arr = [1, 5, 2, 6, 3, 7, 4]
cmds = [[1, 3, 1], [3, 5, 1], [2, 7, 4]]
c1 = (1, 3, 2)
c2 = (3, 5, 7)
c3 = (1, 1, 4)
list(map(lambda i,j,k: arr[i:j][k], c1, c2, c3))