'open' is not defined

dieter dieter at handshake.de
Sat Aug 1 07:50:57 CEST 2015

<ltc.hotspot at gmail.com> writes:
> What about using the append function to remove duplicate outputs entered on or thereafter line no. 9, i.e., 

As far as I know, "append" does not have intelligence in this respect.
Thus, if you need intelligence, your program must implement it.

In cases like yours, I use

  a) added = set(); l = list()
     for x ...
       if x not in added: added.insert(x); l.append(x)


  b) l = list()
     for x ...
       if x not in l: l.append(x)

Note that b) looks more natural - but I prefer a) (if the "x"s are
hashable) as it is slightly more efficient.

> LIST_APPEND(i) Calls list.append(TOS[-i], TOS). Used to implement list comprehensions. While the appended value is popped off, the list object remains on the stack so that it is available for further iterations of the loop. URL link available at https://docs.python.org/2.7/library/dis.html?highlight=append%20list#opcode-LIST_APPEND

Nore that the "dis" module shows you low level Python implementation details
(in fact the byte code of CPython's virtual maschine).
You are not supposed to make direct use of those in your own programs.
> What is the command line for such an append function?

As far as I know, there is none (interpreting "command line" as
"in my program").

The documentation above indicates that the virtual maschine's command
"LIST_APPEND" is used internally to implement Python's "list comprehension"
("[...x... for x in ... if ...]"). Maybe, it is used also for other
purposes, maybe not.

More information about the Python-list mailing list