Hello, I’m trying to do the challenge on the instructions that asks me to make a script without the “|” operator. I have done just that with this line of code. I’m wondering if there is a far more efficient way in doing this, as my line of code is massive. What I am doing is iterating through each digit on the binary number through OR logic on a zip function. In order run the binary numbers through the zip function, I must convert them into lists, run them through the function, and then convert them back to binary.
Here is the code in question:
def binaryORzip(a,b): # Converting binary to lists for the zip function: astring = str(bin(a))[2: ] alist = [int(digit) for digit in astring] bstring = str(bin(b))[2: ] blist =  +[int(digit) for digit in bstring] # Zipping the lists through OR logic: ablist = for digit1,digit2 in zip(alist,blist): if digit1 or digit2 == 1: ablist.append(1) else: ablist.append(0) print ablist # Converting the result of the zip back to binary: abstring = [str(digit) for digit in ablist] abstring2 = ''.join(abstring) abnum = int(abstring2,2) result = bin(abnum) print result return result print binaryORzip(14,5)
The code works, but I am wondering if anyone found a better method on doing this challenge.