Tuple unpacking inside lambda expressions

Sam Ezeh sam.z.ezeh at gmail.com
Sat Apr 16 18:07:23 EDT 2022


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

Oh, of course, completely went past my head.

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

And this works great, thanks!

On Sat, 16 Apr 2022 at 22:42, Chris Angelico <rosuav at gmail.com> wrote:
>
> 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
> --
> https://mail.python.org/mailman/listinfo/python-list


More information about the Python-list mailing list