4 ms·
Its consistent with iteration over a dict: for k in my_dict: print(my_dict[k]) In this example it is implied that unless you specify .items(), you are
by Areading314 8y ago
Its consistent with iteration over a dict:
for k in my_dict:
print(my_dict[k])
In this example it is implied that unless you specify .items(), you are only considering keys in the iteration. This would apply to the + and - operations too as I understand
- ken 8y agoUsing - to mean "here's a dict and a seq -- remove all the seq's keys from the dict" would be useful and consistent, but they specifically prohibit that. They require the rhs to be a dict, too, even though the values are never used. Why?
- Areading314 8y agoGood point, although you'd need to make sure your seq only has unique values. Other than that I don't see why you should have to write {k: v for k, v in d.items() if k not in seq}