dict.update broken?

72 views
Skip to first unread message

Gregg Reynolds

unread,
Feb 14, 2021, 11:36:52 AM2/14/21
to bazel-discuss

dict().update({0: 0, 1: 1})
=> None

According to the docs update should take a dict argument. It should also take a list of pairs:

d = {0: 0, 1: 1}
dict().update(d.items())
=> None

I just need to combine two dictionaries. This should be trivial, but I can't see how to do it.

d...@mobileink.com

unread,
Feb 14, 2021, 11:42:38 AM2/14/21
to bazel-discuss
Never mind.  I keep forgetting I'm not dealing with a functional language, where "update" does not mean "mutate".

d = {0: 0, 1: 1}
d.update({2: 2})
d == {0: 0, 11, 2: 2}

Reply all
Reply to author
Forward
0 new messages