obj2 = ojb1 = range(len(somelist))

Tom Jenkins tjenkins at devis.com
Thu Jan 31 19:45:42 EST 2002


On Thu, 2002-01-31 at 17:28, David Bear wrote:
> I wanted to create 2 distinct lists that were derived from range
> function.  rather that doing
> 
> obj1 = range(len(somelist))
> obj2 = range(len(somelist))
> 
> I wanted to do
> 
> obj2 = ojb1 = range(len(somelist))
> 
> Yet, both names point to the same object -- they're not two objects.
> 
> Is there some other syntax that I could use to avoid having to call
> range(len(list)) twice and still create two objects?

i didn't think this was going to work but hey the interpreter was there
<wink>
>>> l1 = l2[:] = range(len(somelist))
>>> print l1, l2
[0, 1, 2, 3, 4] [0, 1, 2, 3, 4]
>>> print id(l1), id(l2)
135566380 135560684
>>>

-- 

Tom Jenkins
Development InfoStructure
http://www.devis.com






More information about the Python-list mailing list