X-Received: by 10.224.200.202 with SMTP id ex10mr9609559qab.8.1368098693921; Thu, 09 May 2013 04:24:53 -0700 (PDT) X-Received: by 10.50.56.51 with SMTP id x19mr754614igp.0.1368098693883; Thu, 09 May 2013 04:24:53 -0700 (PDT) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!l3no3790446qak.0!news-out.google.com!y6ni20871qax.0!nntp.google.com!m7no3842658qam.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Thu, 9 May 2013 04:24:53 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=123.192.32.215; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw NNTP-Posting-Host: 123.192.32.215 References: <71427882-d2c6-4066-b1e2-624b12a42a0d@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <11dfb7f9-9bbb-4e42-bce9-027efffabcf3@googlegroups.com> Subject: Re: Append to python List From: 88888 Dihedral Injection-Date: Thu, 09 May 2013 11:24:53 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.python:45025 Jussi Piitulainen=E6=96=BC 2013=E5=B9=B45=E6=9C=889=E6=97=A5=E6=98=9F=E6=9C= =9F=E5=9B=9BUTC+8=E4=B8=8B=E5=8D=882=E6=99=8255=E5=88=8620=E7=A7=92=E5=AF= =AB=E9=81=93=EF=BC=9A > RAHUL RAJ writes: >=20 >=20 >=20 > > Checkout the following code: >=20 > >=20 >=20 > > sample2 =3D [x+y for x in range(1,10) for y in range(1,10) if x!=3Dy] = =20 >=20 > > output=3D[] >=20 > > output=3D[x for x in sample2 if x not in output] >=20 > >=20 >=20 > > the output I get is >=20 > > 3 4 5 6 7 8 9 10 3 5 6 7 8 9 10 11 4 5 7 8 9 10 11 12 5 6 7 9 10 11 >=20 > > 12 13 6 7 8 9 11 12 13 14 7 8 9 10 11 13 14 15 8 9 10 11 12 13 15 16 >=20 > > 9 10 11 12 13 14 15 17 10 11 12 13 14 15 16 17 >=20 > >=20 >=20 > > which contains duplicate values. >=20 >=20 >=20 > The second comprehension, [x for x in sample2 if x not in output], in >=20 > the context, is equivalent to [x for x in sample2 if x not in []]. It >=20 > does not refer to an incomplete version of the list that gets assigned >=20 > to the variable after it's done. This is just the handy style for a non-critical loop. In a critical loop, the number of the total operation counts does matter in the execution speed.