How to access index when mapping an enumerated list using a non-lambda function?

318 views Asked by At

I'm mapping over an enumerated list and I'd like to access the index value when I'm not using a lambda function.

For example, I can access index values when using lambda like so:

arr = ['a', 'b', 'c', 'd']

map(lambda (i, v): { i: v }, enumerate(arr))

But I can't do the same when not using lambda:

map(parser, enumerate(arr))

def parser(i, v):
    return { i : v }

The error I get is:

TypeError: parser() takes exactly 2 arguments (1 given)

Why is this the case??

0

There are 0 answers