obj2 = ojb1 = range(len(somelist))

Jeff Shannon jeff at ccvcorp.com
Thu Jan 31 19:09:26 EST 2002


David Bear wrote:

> 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 do

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

or

import copy
obj1 = range(len(somelist))
obj2 = copy.copy(obj1)

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list