[Python-ideas] Tuple Comprehensions

Masklinn masklinn at masklinn.net
Mon Oct 10 08:07:32 CEST 2011


On 2011-10-10, at 04:51 , Mathias Panzenböck wrote:
> 
>> ('banana','loganberry','passion fruit')
>>>>> import operator
>>>>> (operator.concat(_, weapon.strip()) for weapon in freshfruit)
>> 'bananaloganberrypassion fruit'
>> 
> 
> In addition to all previous remarks about the generator expression, what's wrong with the following?
> 
> >>> import operator
> >>> xs=['banana', 'loganberry', 'passion fruit']
> >>> reduce(operator.concat,(x.strip() for x in xs))
I'm guessing the issues (from the original mail) are that it does not benefit from the "concision" ascribed to comprehension (though that concision really is mostly when there isn't a mapping and/or filtering method readily available), and that `reduce` moved to `functools` in Python 3

And of course, for this precise expression you could just do this:

>>> ''.join(x.strip() for x in xs)


More information about the Python-ideas mailing list