Skip to content Skip to sidebar Skip to footer

Convert Comma To Space In List

how can we convert a string [0.0034596999, 0.0034775001, 0.0010091923] to a form [0.0034596999 0.0034775001 0.0010091923] in python. I tried using map, join etc functions but I a

Solution 1:

Using the string method replace() is an efficient solution; however thought I'd offer an alternate using split() and join():

print''.join(i for i in'[0.0034596999, 0.0034775001, 0.0010091923]'.split(','))
>>> [0.0034596999 0.0034775001 0.0010091923]

Solution 2:

"[0.0034596999, 0.0034775001, 0.0010091923]".replace(",", "") returns "[0.0034596999 0.0034775001 0.0010091923]"

Have a look at the string methods - there are many useful ones.

Solution 3:

Just use the string replace() method:

s = '[0.0034596999, 0.0034775001, 0.0010091923]'
s = s.replace(',', '')
print(s)  # -> [0.0034596999 0.0034775001 0.0010091923]

Solution 4:

If it's a string you could do as the other suggested. If it is a list of strings you could do:

new_list_without_comma = [x.replace(",", "") for x in list_with_comma]

Post a Comment for "Convert Comma To Space In List"