Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!ecngs!feeder2.ecngs.de!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'assignment': 0.07; 'subject:getting': 0.07; '[1,': 0.09; 'assigning': 0.09; 'python': 0.11; 'itself.': 0.14; 'assignment.': 0.16; 'output?': 0.16; 'subject:when': 0.16; '>>>': 0.22; 'example': 0.22; '>>>': 0.24; "shouldn't": 0.24; 'friends,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'anyone': 0.31; 'beginning': 0.33; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; '8bit%:9': 0.36; 'like,': 0.36; 'subject:List': 0.36; 'var': 0.36; 'list': 0.37; 'same.': 0.38; 'to:addr:python-list': 0.38; 'explain': 0.39; '12,': 0.39; 'to:addr:python.org': 0.39; '8bit%:6': 0.40; 'entire': 0.61; 'here': 0.66; 'direct': 0.67 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=4Gv//pyJWFxXMaTvS+6P/XJUvP56ldOLIH/U9aicTPA=; b=HYwfBM6ofQjVp1OxUXw+Q0V3N37KtxOqQejP3yCzi8oiqccmBsOxreqkIEUV4N1qjV KmyuuhJLXXxM3WFWBfQBE4wQMp5oPjprhT4QzK0sZ5iK5CYkuZ2k7aVj8ARCnd2/Ylcj +NvMrVjFAGRYjDj5GonsoHkOxEMkTOLS84a5Gvj1gIT6suU15mU7DKl23/mEEP2NcCAe fKcx+3qK91d4DumkRlceEVRvKMWtOA+9Bq+wF2J9fKWlGj9AhAIJlWVjv9AwSH7PFVUN q8CxK6SlH/toGTJXQZTgKbXl0wikcASiuxoxvsp/eseRwNtL6Xdp0dAUiRTa99SedNAy wL0A== MIME-Version: 1.0 X-Received: by 10.194.75.165 with SMTP id d5mr5095388wjw.18.1377402747067; Sat, 24 Aug 2013 20:52:27 -0700 (PDT) Date: Sun, 25 Aug 2013 09:22:27 +0530 Subject: List getting extended when assigned to itself From: Krishnan Shankar To: Python Content-Type: multipart/alternative; boundary=047d7bb04bc273a34d04e4bd9103 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 63 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377402755 news.xs4all.nl 15892 [2001:888:2000:d::a6]:57881 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52962 --047d7bb04bc273a34d04e4bd9103 Content-Type: text/plain; charset=ISO-8859-1 Hi Python Friends, I came across an example which is as below, >>> var = [1, 12, 123, 1234] >>> var [1, 12, 123, 1234] >>> var[:0] [] >>> var[:0] = var >>> var [1, 12, 123, 1234, 1, 12, 123, 1234] >>> Here in var[:0] = var we are assigning an entire list to the beginning of itself. So shouldn't it be something like, [[1, 12, 123, 1234], 1, 12, 123, 1234] It happens when we do the below, >>> var = [1, 12, 123, 1234] >>> var[0] = var >>> var [[...], 12, 123, 1234] >>> Literally var[0] = var and var[:0] = var almost meens the same. But why is the difference in output? Can anyone explain what happens when slicing assignment and direct assignment. Regards, Krishnan --047d7bb04bc273a34d04e4bd9103 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi Python Friends,

I came across = an example which is as below,

>= ;>> var =3D [1, 12, 123, 1234]
>>> var
[= 1, 12, 123, 1234]
>>> var[:0]
[]
>>> var[:0] =3D v= ar
>>> var
[1, 12, 123, 1234, 1, 12, 123, 1234= ]
>>>=A0

Here in var[:0] = =3D var we are assigning an entire list to the beginning of itself. So=A0sh= ouldn't=A0it be something like,

[[1, 12, 123, 1234], 1, 12, 123, 1234]

It happens when we do the below= ,

>>> var =3D [1, 12, 123, 1234]
>>> var[0] =3D var
>>> var
[[...= ], 12, 123, 1234]
>>>=A0

Literally var[0] =3D var and var[:0] =3D var almost meens the same. B= ut why is the difference in output? Can anyone explain what happens when sl= icing=A0assignment=A0and direct assignment.

Regards,
Krishnan
--047d7bb04bc273a34d04e4bd9103--