[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: Newbie question: Allocation vs references
From:       Steven Bethard <steven.bethard () gmail ! com>
Date:       2005-06-02 16:31:31
Message-ID: AaSdnZZ92pT-qQLfRVn-sQ () comcast ! com
[Download RAW message or body]

Stian Søiland wrote:
> There are several ways to create a copy of a list:
[snip]
> a2 = list(a)       # create a new list object out of any sequence

I'll just point out that FWIW, this is by far my favorite idiom of the 
ones offered because it applies to pretty much all the builtin container 
types:

py> d = {1:42, -37:0}
py> d2 = dict(d)
py> d == d2, d is d2
(True, False)
py> s = set(['a', 'd', 'e'])
py> s2 = set(s)
py> s == s2, s is s2
(True, False)
py> L = [3.14, 0.707]
py> L2 = list(L)
py> L == L2, L is L2
(True, False)

STeVe
-- 
http://mail.python.org/mailman/listinfo/python-list

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic