Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52963
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!eweka.nl!hq-usenetpeers.eweka.nl!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <bsk16@case.edu> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.010 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'assignment': 0.07; 'element': 0.07; 'subject:getting': 0.07; '[1,': 0.09; 'assigning': 0.09; 'python': 0.11; 'itself.': 0.14; '24,': 0.16; 'assignment.': 0.16; 'integer.': 0.16; 'output?': 0.16; 'subject:when': 0.16; 'sat,': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'example': 0.22; 'aug': 0.22; 'to:name:python-list@python.org': 0.22; "shouldn't": 0.24; 'header:In-Reply-To:1': 0.27; 'friends,': 0.30; 'message-id:@mail.gmail.com': 0.30; '>>>>': 0.31; 'piece': 0.31; 'anyone': 0.31; 'says': 0.33; 'beginning': 0.33; 'received:74.125.82': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'like,': 0.36; 'subject:List': 0.36; 'var': 0.36; 'should': 0.36; 'list': 0.37; 'list.': 0.37; 'same.': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'explain': 0.39; 'received:74.125': 0.39; '12,': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'entire': 0.61; 'more': 0.64; 'here': 0.66; 'direct': 0.67; 'different.': 0.84; '2013': 0.98 |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=659kEWVvzJVVJml1VBX4guCQSyOQXyLAP0DdsgHlAzI=; b=YETQP+ga7yLJ4+/2QoT/xhqFVbClQLLTUFa04z35883nNFoWTmV/1nhoEcVuykBSKq efzxNZExOaQH6nEi1eWfXAuPiJD8yArod6UYIiSzd5VAu1ASkP9ZyZIcj+I5TPLec0ak ioR0EmGcr73NODlfGi/xjEzewKaHtFgZlqDwL0A27GK05n0OUSiMFp7bFXVP75PU1WtG aGVC1imAW6n9xd2d9I5SSIl2hoLdYRsDEilIP1sAiub00YjMbdJTKTzkGdvTap2MTE3Q 70z/4+IE4KL5ra3Vu5h70467Nt6cVKEJROSaPYAWVTDKp5pD7v6+cnqiAKwgvw1/fuJx 3J5A== |
| X-Gm-Message-State | ALoCoQmdj3ZxMjyHdg3qcdJNc6iPDOTZy4lGJO8rInyMkx5+dbO0f9Fs4HofJxBjsSaPY2KS/mcBnC9z19+BuBbsuLgaXCBkvNCXLF9IOmhB0W1CCGmh7pHJH+DPgl5coGiG2nCi0uPqF0zwWUAxUL54PXM7IuJgLg== |
| X-Received | by 10.180.75.205 with SMTP id e13mr3192652wiw.29.1377403422241; Sat, 24 Aug 2013 21:03:42 -0700 (PDT) |
| X-Received | by 10.180.75.205 with SMTP id e13mr3192649wiw.29.1377403422170; Sat, 24 Aug 2013 21:03:42 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <CAL0E0u5iRMy5-veEfy5d68u16CM3U+ptqRzG68zs4rxf7uLfaQ@mail.gmail.com> |
| References | <CAL0E0u5iRMy5-veEfy5d68u16CM3U+ptqRzG68zs4rxf7uLfaQ@mail.gmail.com> |
| From | Benjamin Kaplan <benjamin.kaplan@case.edu> |
| Date | Sat, 24 Aug 2013 21:03:22 -0700 |
| Subject | Re: List getting extended when assigned to itself |
| To | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-Junkmail-Whitelist | YES (by domain whitelist at mpv1.tis.cwru.edu) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.207.1377403426.19984.python-list@python.org> (permalink) |
| Lines | 44 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1377403426 news.xs4all.nl 15898 [2001:888:2000:d::a6]:60745 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:52963 |
Show key headers only | View raw
On Sat, Aug 24, 2013 at 8:52 PM, Krishnan Shankar <i.am.songoku@gmail.com> wrote: > 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. Are you sure they're almost the same? >>> var[0] 1 >>> var[:0] [] One's a list and one is an integer. It's hard for them to be any more different. var[0] means that you should be setting an element of the list. var[:0] says you want to update a piece of the list, not an element inside it.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: List getting extended when assigned to itself Benjamin Kaplan <benjamin.kaplan@case.edu> - 2013-08-24 21:03 -0700
csiph-web