Python: Concatenate Integer Items In A List To A Single String
Is there a better way of the following for concatenating items in a list that are 'integers' into a string: import numpy as np my_list = [1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0] change
Solution 1:
Im not sure what you mean by better, but you could try this.
''.join([str(x) for x in my_list])
Solution 2:
how about this?
''.join([str(item) for item in my_list])
Solution 3:
You can use the bitstring
module:
>>>from bitstring import BitArray>>>f'{BitArray(my_list).uint:b}'
'110000111010'
Post a Comment for "Python: Concatenate Integer Items In A List To A Single String"