obj2 = ojb1 = range(len(somelist))
Cliff Wells
logiplexsoftware at earthlink.net
Thu Jan 31 17:37:14 EST 2002
On 31 Jan 2002 15:28:49 -0700
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?
You could use copy.copy:
import copy
obj1 = range(len(somelist))
obj2 = copy.copy(obj1)
--
Cliff Wells
Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308
(800) 735-0555 x308
"Then with your new power you'll accomplish all sorts of cool stuff
in no time, and We'll All Be Sorry. At that point you can either
gloat a bit, and then relent, or go ahead and send the robot army
after us." - Quinn Dunkan
More information about the Python-list
mailing list