Created
February 22, 2015 22:28
-
-
Save saxbophone/5c1bacc1960a8eda1b88 to your computer and use it in GitHub Desktop.
Python Recursive XOR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from operator import xor as _xor_ | |
def xor(a, b): | |
try: | |
if len(a) is not 1 and len(b) is not 1: | |
result = [] | |
for i in range(0,len(a)): | |
result.append(xor(a[i], b[i])) | |
return result | |
else: | |
if isinstance(a, str): | |
a = ord(a) | |
if isinstance(b, str): | |
b = ord(b) | |
return _xor_(a, b) | |
except TypeError: | |
return _xor_(a, b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment