[Python-ideas] Allow specifying list of functions to `map`

Chris Angelico rosuav at gmail.com
Mon Mar 31 00:00:47 CEST 2014


On Mon, Mar 31, 2014 at 4:59 AM, Ram Rachum <ram.rachum at gmail.com> wrote:
> If `map` accepted a tuple for its first argument, things like this:
>
>     stdout, stderr = map(str.strip, map(bytes.decode, popen.communicate()))
>
> Could become this:
>
>     stdout, stderr = map((bytes.decode, str.strip), popen.communicate())

stdout, stderr = map(lambda x: x.decode().strip(), popen.communicate())

Or:

stdout, stderr = popen.communicate()
stdout = stdout.decode().strip()
stderr = stderr.decode().strip()

Yes, the latter is a bit of duplication, but it's clear what's going
on. (Obviously appropriate only where you know exactly how many
elements there'll be, as in your example.)

ChrisA


More information about the Python-ideas mailing list