i want to make function to make from 1111 into 1 and 0000 into 0.
for the example:
Input:
['1111', '1111', '0000', '1111', '1111', '0000', '1111', '0000', '0000', '1111', '0000', '0000', '0000', '0000', '0000', '0000', '0000', '1111', '0000', '0000', '1111', '1111', '0000', '0000', '0000', '0000', '1111', '0000', '1111', '1111', '0000', '0000']
Desired output:
11011010010000000100110000101100
But i don't know how to make it or the algorithm. Can you help me?
My attempt so far:
def bagiskalar(biner):
print(biner)
biner = str(biner)
n = 4
hasil = []
potong = [biner[i:i+n] for i in range(0, len(biner), n)]
for a in potong:
hasil = potong.append(a)
return hasil
You can easily use list comprehension and the
join()method: