3 ms·
I agree. Though a more useful constructor would be nice for naked dicts. I've created a helper function that allows for nicer construction of dicts based on oth
by io41 15y ago
I agree.
Though a more useful constructor would be nice for naked dicts. I've created a helper function that allows for nicer construction of dicts based on other dicts and potential new fields:
https://gist.github.com/24651d78d3f1e3dec6f4 https://gist.github.com/24651d78d3f1e3dec6f4 :
def new_dict(args, *kwargs):
"""
Create new dicts
>>> new_dict({1:2}, {2:5}, foo=5)
{1: 2, 2: 5, 'foo': 5}
"""
d = {}
for arg in args:
d.update(arg)
d.update(kwargs)
return d
d = new_dict(old_dict1, old_dict2, old_dictN, foo='bar')