obj2 = ojb1 = range(len(somelist))

Paul Rubin phr-n2002a at nightsong.com
Thu Jan 31 18:17:11 EST 2002


David Bear <iddwb at moroni.pp.asu.edu> writes:
> 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?

obj1 = range(len(somelist))
obj2 = obj1[:]

I don't see why that's any better though.



More information about the Python-list mailing list