Skip to content
Advertisement

how can I split the elements of a list of binary numbers?

I’m trying to split the elements of a list of binary numbers as follows :

bin_list=['000101111000','011110111011']

Expected result: bin_list=[[0,0,0,1,0,1,1,1,1,0,0,0],[0,1,1,1,1,0,1,1,1,0,1,1]]

I think that would be a list of a list of integers what I’m trying to get?? I tried searching a similar procedure and I’ve tried some but I can’t get it right pls help

thanks!!

Advertisement

Answer

This could be done with nesting list comprehensions:

>>> bin_list = ['000101111000','011110111011']
>>> [[int(n) for n in ns] for ns in bin_list]
[[0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0], [0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1]]
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement