[Python-Dev] Don't set local variable in a list comprehension or generator (original) (raw)

Nadeem Vawda nadeem.vawda at gmail.com
Wed May 18 16:19:59 CEST 2011


On Wed, May 18, 2011 at 2:21 PM, Victor Stinner <victor.stinner at haypocalc.com> wrote:

''.join(c for c in 'abc') and ''.join([c for c in 'abc']) do create a temporary c variable.

I'm not sure why you would encounter code like that in the first place. Surely any code of the form:

''.join(c for c in my_string)

would just return my_string? Or am I missing something?

I heard about optimization in the AST tree instead of working on the bytecode. What is the status of this project?

Are you referring to issue11549? There was some related discussion [1] on python-dev about six weeks ago, but I haven't seen anything on the topic since then.

Cheers, Nadeem

[1] http://mail.python.org/pipermail/python-dev/2011-April/110399.html



More information about the Python-Dev mailing list