Alexander Belopolsky added the comment: The patch looks reasonable to me. Bytecode docs need to be changed. At minimum like this: =================================================================== --- Doc/library/dis.rst (revision 61097) +++ Doc/library/dis.rst (working copy) @@ -463,9 +463,9 @@ address to jump to (which should be a ``FOR_ITER`` instruction). -.. opcode:: LIST_APPEND () +.. opcode:: LIST_APPEND (i) - Calls ``list.append(TOS1, TOS)``. Used to implement list comprehensions. + Calls ``list.append(TOS[-i], TOS)``. Used to implement list comprehensions. .. opcode:: LOAD_LOCALS () ========
More explanation on TOS being removed while TOS[-i] (obviously) not may be in order. For py3k similar optimization should be available for dict and set comprehensions. More unit tests will be helpful, particularly for nested iterations such as [(x,y,z) for x in s for y in s for z in s]. ---------- nosy: +belopolsky __________________________________ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2183> __________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com