3 ms·
bool({}) should raise an exception, if we're being strict. You could try to define the addition of keys like you suggest, but you need to force a value type wh
by barakm 13y ago
bool({}) should raise an exception, if we're being strict.
You could try to define the addition of keys like you suggest, but you need to force a value type which defines a + operation into the same type. Which is what Counter() does, below (appending strings).
Python is dynamically typed, so you can't maintain these expectations. Therefore, summation and bool({}) should be an error, or merely "true" (ie, yes, it exists, and is not None) -- as per the original thread and resolution.
- dalke 13y agoGood thing Python isn't a strict language then. That would be Scheme. ;)