Currently one row of my csv file looks like this :
314523, 165538, 76255, 335416, 416827 1250536:1 1744638:1 298526:1 1568238:1
I need it to look like this :
314523,165538,76255,335416,416827 1250536:1 1744638:1 298526:1 1568238:1
I only want to remove the spaces after or before commas and leave the other blank spaces as it is.
How can I do this in python?
Note : I am a beginner in python
I would recommend using the replace function. You enter the pattern you want to replace. In your example, the pattern is comma space (', ')
and space comma (' ,')
. Then say what you want to replace the pattern with (',')
.
line=line.replace(', ', ',').replace(' ,',',')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With