Preferred method for "Assignment by value"

duncan smith buzzard at
Tue Apr 15 21:07:14 CEST 2008

hall.jeff at wrote:
> Thank you both, the assigning using slicing works perfectly (as I'm
> sure you knew it would)... It just didn't occur to me because it
> seemed a little nonintuitive... The specific application was
> def dicttolist (inputdict):
>     finallist=[]
>     for k, v in inputdict.iteritems():
>         temp = v
>         temp.insert(0,k)
>         finallist.append(temp)
>     return finallist


finallist = [[k] + v for k, v in inputdict.iteritems()]

the list concatenation creating new lists.


More information about the Python-list mailing list