Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #94829

Re: 'open' is not defined

From dieter <dieter@handshake.de>
Subject Re: 'open' is not defined
Date 2015-08-01 07:50 +0200
References <55babad0.c25e460a.2b9e.ffffb3cd@mx.google.com> <87si84hmmh.fsf@handshake.de> <55bb181c.6567460a.a006c.fffff5f1@mx.google.com>
Newsgroups comp.lang.python
Message-ID <mailman.1123.1438408269.3674.python-list@python.org> (permalink)

Show all headers | View raw


<ltc.hotspot@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)

or

  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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: 'open' is not defined dieter <dieter@handshake.de> - 2015-08-01 07:50 +0200

csiph-web