Re:Please reconsider the Boolean evaluation of midnight
by mctx on Thursday March 06, 2014 @08:54PM
(#7357995)
{1: ["A", "B"]}?
[ Parent
| on HN ]
Re:Please reconsider the Boolean evaluation of midnight
by dalke on Thursday March 06, 2014 @09:22PM
(#7358132)
Okay, then what about
{1: "A"} + {}
Should that return {1: ["A"]}? In which case {} is no longer a zero value.What about
{1: "A"} + {} + {1: "B", 2: "Z"} + {1: "C"} + {}
In any case, your suggestion would break all existing code. Based on all the StackOverflow and python-list questions, most people expect one or the other value, and few want the two-element list containing both. (And why a list instead of a tuple?)Guido chose the current behavior because there is no clear-cut winner. "Refuse the temptation to guess."
Re:Please reconsider the Boolean evaluation of midnight
by einhverfr on Friday March 07, 2014 @05:45AM
(#7359529)
This could be interesting. One would have to define what hash math should mean. Personally, I would expect (based on my naive assumptions here) that:
{1: "A"} + {} == {1: "A"}
but {1: "A"} + {} + {1: "B", 2: "Z"} + {1: "C"} + {}
should reduce to: {1: ("A" + "B" + "C"), 2: "Z"}
Whether you can add "A", "B", and "C" would depend on string functions (could be "ABC" or raise an exception that these cannot be added for example).
Re:Please reconsider the Boolean evaluation of midnight
by aiiane on Thursday March 06, 2014 @11:30PM
(#7358515)
How does {1:"A"}+{} = {1:"A"} imply that {} is no longer a zero value? 1+0=1 makes total sense...
Re:Please reconsider the Boolean evaluation of midnight
by dalke on Friday March 07, 2014 @12:36AM
(#7358677)
It's not just that one expression, but when done in addition to the previous suggested answer. That is, what is the type of the values in the summed dictionaries?
If {1:"A"}+{} == {1:"A"} then the type of each value is unchanged from the input list.
If {1:"A"}+{1:"B"} == {1:["A","B"]} then the type of each value (or at least each shared value) is a 2-element list.
If both are true, then no one can write sane code which knows how deal with the sum of two dictionaries.
That is, the insane code has to have checks for if one of the dictionaries is empty, and if so, do one thing, otherwise do another thing. In which case, why is this definition useful?
Therefore, either {} is the zero value, or dictionary summation produces lists for the resulting values, but not both.