back-references in comprehensions

Hi, I would like to use backreferences in list comprehensions (or other comprehensions), such as : [[elt for elt in lst if elt] for lst in matrix if \{1}] # \{1} is back-reference to filter result of the # first comprehension ([elt for elt in lst if elt]) It would be possible to do this ? Thanks

On 2011-10-08 19:48, yoch melka wrote:
I don't think the syntax you propose is going to fly, but a similar feature has been discussed before on this list. I prefer this version: [[elt for elt in lst if elt] as r for lst in matrix if r] But I don't have much hope that it will ever get in. FWIW, the example can already be written in several ways in current python, e.g.: 1) [r for lst in matrix for r in ([elt for elt in lst if elt],) if r] 2) filter(None, ([elt for elt in lst if elt] for lst in matrix)) HTH - Jacob

On 2011-10-08 19:48, yoch melka wrote:
I don't think the syntax you propose is going to fly, but a similar feature has been discussed before on this list. I prefer this version: [[elt for elt in lst if elt] as r for lst in matrix if r] But I don't have much hope that it will ever get in. FWIW, the example can already be written in several ways in current python, e.g.: 1) [r for lst in matrix for r in ([elt for elt in lst if elt],) if r] 2) filter(None, ([elt for elt in lst if elt] for lst in matrix)) HTH - Jacob
participants (2)
-
Jacob Holm
-
yoch melka