Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #94829 > unrolled thread
| Started by | dieter <dieter@handshake.de> |
|---|---|
| First post | 2015-08-01 07:50 +0200 |
| Last post | 2015-08-01 07:50 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: 'open' is not defined dieter <dieter@handshake.de> - 2015-08-01 07:50 +0200
| From | dieter <dieter@handshake.de> |
|---|---|
| Date | 2015-08-01 07:50 +0200 |
| Subject | Re: 'open' is not defined |
| Message-ID | <mailman.1123.1438408269.3674.python-list@python.org> |
<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 top | Article view | comp.lang.python
csiph-web