python dict.fromkeys() returns empty

Posted by slooow on Stack Overflow See other posts from Stack Overflow or by slooow
Published on 2010-03-31T23:27:09Z Indexed on 2010/03/31 23:33 UTC
Read the original article Hit count: 160

Filed under:
|
|

I wrote the following function. It returns an empty dictionary when it should not. The code works on the command line without function. However I cannot see what is wrong with the function, so I have to appeal to your collective intelligence.

def enter_users_into_dict(userlist):
    newusr = {}
    newusr.fromkeys(userlist, 0)
    return newusr

ul = ['john', 'mabel']
nd = enter_users_into_dict(ul)
print nd

It returns an empty dict {} where I would expect {'john': 0, 'mabel': 0}.

It is probably very simply but I don't see the solution.

© Stack Overflow or respective owner

Related posts about python

Related posts about dict