Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'think,': 0.07; 'definition,': 0.09; 'things,': 0.09; 'will,': 0.09; 'cc:addr :python-list': 0.11; '(and,': 0.16; '37,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'identities': 0.16; 'numpy': 0.16; 'objects.': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'feb': 0.22; '>>>': 0.22; 'import': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; '15,': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'subject:list': 0.30; 'message- id:@mail.gmail.com': 0.30; '>>>>': 0.31; 'keys': 0.31; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'right?': 0.36; 'so,': 0.37; 'two': 0.37; 'christian': 0.38; 'pm,': 0.38; 'affect': 0.61; 'show': 0.63; 'different': 0.65; 'other.': 0.75; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=iL4jFRsuKJhmTrgfBM36PHnQXIQFEl0agARzZHphBHw=; b=x6XJaIB8xm7Bbeqo9Vt+VtMXS7NsVN4qaIiF80ES1ZBwnRZpM050Brol8Cy0ELsEPd iLoyxP+HUNTtUvdbP2p6IVNixlhttWzPMQTacR0IZlHfaIYnzX2aUdYjowrhieX8Rwnt KfdAvxTCSVzkWxHXIzDk12XWdORhbiAXsy6hTnPuGAqjuZEz2LUjw0SsM64BX0ktdxU3 eY7I7910pKW5a4ALjrmXT73hEbtMEWiWf9xH/Z7/8z77jQOSozKrmALL4PPpV0K8JaKg 1br+HYFYW1yGwZIH9AHs37UXdZKMhETTR9Nd5a2irxgeTyfBQTaanq4tcM1ogsHS2n4h BfYw== MIME-Version: 1.0 X-Received: by 10.66.26.176 with SMTP id m16mr14887362pag.142.1392463289528; Sat, 15 Feb 2014 03:21:29 -0800 (PST) In-Reply-To: References: <13208de8-0f85-4e60-b059-dc087c8fda41@googlegroups.com> <917ede6d-db7c-4a8c-8203-27677283776b@googlegroups.com> <871tz5piy0.fsf@elektro.pacujo.net> <87vbwho1i0.fsf@elektro.pacujo.net> <87mwhtnzdu.fsf@elektro.pacujo.net> Date: Sat, 15 Feb 2014 22:21:29 +1100 Subject: Re: Explanation of list reference From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392463292 news.xs4all.nl 2964 [2001:888:2000:d::a6]:51812 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66413 On Sat, Feb 15, 2014 at 8:44 PM, Christian Gollwitzer wrote: >>>> import numpy as np >>>> a=np.array([1, 2, 3, 4]) >>>> b=a[:] >>>> id(a) > 140267900969344 >>>> id(b) > 140267901045920 > > So, a and b are different things, right? > >>>> b[1]=37 >>>> b > array([ 1, 37, 3, 4]) >>>> a > array([ 1, 37, 3, 4]) > > Still they are connected. Well, yes, they are different things; but that doesn't mean they can't affect each other. And you don't need numpy to see that: >>> d = {} >>> k1 = d.keys() >>> k2 = d.keys() >>> k1 is k2 False >>> k1 == k2 True >>> d[1]=1 >>> k1 dict_keys([1]) >>> k2 dict_keys([1]) Two separate keys views on the same dictionary will, by definition, always show the same keys (and, I think, in the same order). But they're still separate objects. Their identities are distinct, their values are linked. ChrisA