Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'append': 0.07; "subject:' ": 0.07; '"in': 0.09; 'indicates': 0.09; 'internally': 0.09; 'loop.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'programs.': 0.11; 'subject:not': 0.11; 'stack': 0.13; '"list': 0.16; 'added:': 0.16; 'function?': 0.16; 'i.e.,': 0.16; 'outputs': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'byte': 0.18; 'duplicate': 0.18; '(in': 0.18; "python's": 0.23; 'slightly': 0.23; 'module': 0.25; 'header:User-Agent:1': 0.26; 'command': 0.26; 'header:X -Complaints-To:1': 0.26; 'entered': 0.27; 'not.': 0.27; 'function': 0.28; 'looks': 0.29; 'thus,': 0.29; 'code': 0.30; 'supposed': 0.31; 'implement': 0.32; 'maybe': 0.33; 'url:python': 0.33; 'purposes,': 0.33; 'list': 0.34; 'level': 0.35; 'but': 0.36; 'there': 0.36; 'url:org': 0.36; 'cases': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'received:org': 0.37; 'charset :us-ascii': 0.37; 'virtual': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'your': 0.60; 'no.': 0.62; 'further': 0.62; 'details': 0.62; 'more': 0.63; 'url:%20': 0.63; 'received:217': 0.66; 'natural': 0.67; 'direct': 0.68; 'low': 0.83; 'off,': 0.84; 'respect.': 0.84; 'maybe,': 0.91; 'thereafter': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: dieter Subject: Re: 'open' is not defined Date: Sat, 01 Aug 2015 07:50:57 +0200 References: <55babad0.c25e460a.2b9e.ffffb3cd@mx.google.com> <87si84hmmh.fsf@handshake.de> <55bb181c.6567460a.a006c.fffff5f1@mx.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gmane-NNTP-Posting-Host: pd9e084ad.dip0.t-ipconnect.de User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) Cancel-Lock: sha1:1SY2E9Dj7g/8+gC8/ytAJ5MwaUM= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1438408269 news.xs4all.nl 2832 [2001:888:2000:d::a6]:58357 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!news.stben.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:94829 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.