5 ms·
Ah, great. This used to be rather clunky to do.
by joelthelion 9y ago
Ah, great. This used to be rather clunky to do.
- saurik 9y agoReally? This is how that was done in Python 2.7 and it doesn't seem that much clunkier to me... dict(dict1, **dict2)
- heinrich5991 9y agoThat's only allowed if the keys in the second dictionary are valid Python identifiers (don't contain spaces etc.). I think CPython is OK with this, but PyPy is not.
- snthpy 9y agoInteresting. I never thought of that. I also asked a question about this on StackOver flow once and no one suggested that. Very useful.
- joelthelion 9y agoIt has a lot of issues. The biggest one for me is the following: Dicts are intended to take hashable keys (e.g. frozensets or tuples), but this method fails in Python 3 when keys are not strings. Source: https://stackoverflow.com/questions/38987/how-to-merge-two-dictionaries-in-a-single-expression https://stackoverflow.com/questions/38987/how-to-merge-two-d...