circuitpython/tests/basics/dict_update.py
Damien George bcb6ca4d5e py: Implement full behaviour of dict.update(), and dict().
Add keyword args to dict.update(), and ability to take a dictionary as
argument.

dict() class constructor can now use dict.update() directly.

This patch loses fast path for dict(other_dict), but is that really
needed?  Any anyway, this idiom will now re-hash the dictionary, so is
arguably more memory efficient.

Addresses issue #647.
2014-06-03 12:53:44 +01:00

17 lines
231 B
Python

d = {1:2, 3:4}
print(len(d))
d.update(["ab"])
print(d[1])
print(d[3])
print(d["a"])
print(len(d))
d.update([(1,4)])
print(d[1])
print(len(d))
# using keywords
d.update(a=5)
print(d['a'])
d.update([(1,5)], b=6)
print(d[1], d['b'])