how to remove space in string list python

Question:

So i have list contains with 1 string.

biner_pass = [‘00001111000000000000111111111111
00001111111111111111000011111111 11111111111100000000000000000000
11111111111111110000111111111111′]

all i want is to remove the space and join all the binary.

i was trying using
binerpass = ''.join(biner_pass.split(' ')) or biner_pass.replace(" ", "") but it cannot work. so how to remove space?

Asked By: HelpMeInDjango

||

Answers:

IIUC, You can use replace.

biner_pass = ['0000111100000000000011111111111100001111111111111111000011111111 1111111111110000000000000000000011111111111111110000111111111111']
biner_pass[0] = biner_pass[0].replace(" ", "")
print(biner_pass)

Output:

['00001111000000000000111111111111000011111111111111110000111111111111111111110000000000000000000011111111111111110000111111111111']
Answered By: I'mahdi

You need to do it for each element of the list

biner_pass = [b.replace(' ','') for b in biner_pass]
Answered By: depperm

The string is the 0-th element of a list with 1 element. Therefore you need

biner_pass[0].replace(" ", "")
Answered By: Alberto Garcia

binary will be a string that conatains 1 and 0 without spaces

binary = "".join(biner_pass).replace(" ", "")
Answered By: Omer Dagry
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.