On Thu, Oct 24, 2019 at 1:20 AM Christopher Barker <[email protected]> wrote:
>
> On Wed, Oct 23, 2019 at 5:42 AM Rhodri James <[email protected]> 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 <[email protected]>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/WWCQBMRZGLAKBK5M4LNZLG3CBURHR3FK/
Code of Conduct: http://python.org/psf/codeofconduct/