[Python-ideas] Allow specifying list of functions to `map`
MRAB
python at mrabarnett.plus.com
Mon Mar 31 00:24:30 CEST 2014
On 2014-03-30 23:00, Chris Angelico wrote:
> 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()
>
Or:
stdout, stderr = (x.decode().strip() for x in popen.communicate())
for that matter.
> 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.)
>
More information about the Python-ideas
mailing list