[Tutor] map & lambda to create dictionary from lists?
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Fri, 24 Aug 2001 13:44:59 -0700 (PDT)
On Fri, 24 Aug 2001, Danny Yoo wrote:
> I'm not sure if this is better; tell me what you think of this approach:
>
> ###
> def itemsToDict(items):
> dict = {}
> for key, value in items:
> dict[key] = value
Doh! That's what I get for not checking my code. I meant to write:
###
def itemsToDict(items):
dict = {}
for key, value in items:
dict[key] = value
return dict
###
I had forgotten to return the dictionary back to the user. Sorry about
that.