Preferred method for "Assignment by value"

Robin Stocker robin at nibor.org
Tue Apr 15 15:25:43 EDT 2008


hall.jeff at gmail.com schrieb:
> by changing temp = v[:] the code worked perfectly (although changing
> temp.insert(0,k) to temp = [k] + temp also worked fine... I didn't
> like that as I knew it was a workaround)

So the for body now looks like this?:

   temp = v[:]
   temp.insert(0, k)
   finallist.append(temp)

It can still be clarified and simplified to this (may also be faster):

   temp = [k] + v
   finallist.append(temp)

Which one do you like better :)?

   Robin



More information about the Python-list mailing list