3 ms·
For sets I can understand what + and - means: you can add or subtract the sets (not add or remove an element directly). This should be like lists, e.g. [10
by amelius 8y ago
For sets I can understand what + and - means: you can add or subtract the sets (not add or remove an element directly). This should be like lists, e.g.
[10,20] + [30]
But what + and - would mean in the case of dicts is obscure. Better to just use full method names imho.
- deleted 8y ago[deleted]
- sametmax 8y agoAll my students disagree with you. They all try addition, and all expect a resulting dict with keys from both dicts. The fact the keys from the one side are prioritized is something they will learn once, just like with dict.update().
- amelius 8y agoThat's something a student may learn. But there will be plenty of people reading Python code that don't know how "+" works on dicts; and it is difficult to find out what it does because you can't easily Google/grep for the function name. Doing experiments with dicts is not something you want to be doing while you are reading other people's code.