Hello Python Ideas,
To quote the tutorial, "List comprehensions provide a concise way to create lists without resorting to use of map(), filter() and/or lambda.".
There are a couple of constraints in the above definition that I feel could be overcome. For one thing, list comprehensions don't let you create immutable sequences (such as a tuple) by design. For another, it does not provide a concise alternative to reduce() function.
To address both of the above, I'd like to introduce tuple comprehensions, which would work like so:
>>> freshfruit = [' banana', ' loganberry ', 'passion fruit ']As you can see, we use parenthesis instead of square brackets around the comprehension.
>>> (weapon.strip() for weapon in freshfruit)
('banana', 'loganberry', 'passion fruit')
>>> import operator
>>> (operator.concat(_, weapon.strip()) for weapon in freshfruit)
'bananaloganberrypassion fruit'