On Wed, Nov 19, 2014 at 9:54 AM, Terry Reedy tjreedy@udel.edu wrote:
On 11/18/2014 12:40 PM, Wolfgang Maier wrote:
I just remembered one use of the current behavior. Two years ago or so, I was suggesting on this list a possibility for early termination of comprehensions when a particular value is encountered. In other words, an equivalent to:
l = [] for x in seq: if x == y: break l.append(x)
I believe I thought then that one should write the explicit loop rather than overload the 'comprehension' concept.
I'm not sure about that. Comprehensions can already be filtered; is it such a jump from there to a "filter" that aborts on a certain condition? It may not be language-supported, but I don't see that it's illogical; and any use of a loop that appends to a list is rightly considered code smell.
ChrisA