
On Thu, Oct 24, 2019 at 1:20 AM Christopher Barker <pythonchb@gmail.com> wrote:
On Wed, Oct 23, 2019 at 5:42 AM Rhodri James <rhodri@kynesim.co.uk> wrote:
frankly, the | is obscure to most of us. And it started as "bitwise or", and evokes the __or__ magic method -- so why are we all convinced that somehow it's inextricably linked to "set union"?
It is because "bitwise or" is very similar to "set union". You can regard integer as bitset (set of bits). 5 is {bit 1, bit 3} and 6 is {bit 2, bit 3}. So 5 | 4 is 7 {bit 1, bit 2, bit 3}. So reusing | to set union is very natural to me. But if we use + for dict merging, I think we should add + to set too. Then the set has `.union()`, `|` and `+` for the same behavior. Regards, -- Inada Naoki <songofacandy@gmail.com>