17.05.18 13:53, Ken Hilton пише:
We all know the bitwise operators: & (and), | (or), ^ (xor), and ~
(not). We know how they work with numbers:
420 ^ 502
110100100
111110110
== XOR ==
001010010
= 82
But it might be useful in some cases to (let's say) xor a string (or
bytestring):
The question is how common a need of these operations? If it is not
common enough, they are better be implemented as functions in a
third-party library.
Currently, that's done with this expression for strings:
>>> ''.join(chr(ord(a) ^ ord(b)) for a, b in zip('HELLO', 'world'))
'?*> +'
Are you aware that this can raise a ValueError for some input strings?
For example for '\U00100000' and '\U00010000'.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/