Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert comma to space in list

Tags:

python

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 am unable to do so. Can anyone help?

like image 202
shaifali Gupta Avatar asked Mar 11 '23 12:03

shaifali Gupta


2 Answers

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]
like image 138
ospahiu Avatar answered Mar 20 '23 08:03

ospahiu


"[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.

like image 34
janbrohl Avatar answered Mar 20 '23 08:03

janbrohl