Tuple unpacking inside lambda expressions

Chris Angelico rosuav at gmail.com
Sat Apr 16 17:40:33 EDT 2022


On Sun, 17 Apr 2022 at 07:37, Sam Ezeh <sam.z.ezeh at gmail.com> wrote:
>
> Two questions here.
>
> Firstly, does anybody know of existing discussions (e.g. on here or on
> python-ideas) relating to unpacking inside lambda expressions?
>
> I found myself wanting to write the following.
>
> ```
> map(
>     lambda (module, data): result.process(module, data),
>      jobs
> )
> ```
> However, it's of course not legal Python syntax.

What about:

[result.process(module, data) for module, data in jobs]

(or with () instead of [] around the outside if you want a generator)?

In general, if you're using map() with a lambda function, it's often
simpler to switch to a comprehension.

ChrisA


More information about the Python-list mailing list