-1

This is my string "INDUSTRIAL, PARKS, PROPERTY" I want to delete the spaces trailing parks, property. I want the output as "INDUSTRIAL,PARKS,PROPERTY"

xJokerx
  • 21
  • 1
  • 3
  • If you search in your browser for "Python remove spaces from line", you'll find references that can explain this much better than we can manage here. – Prune Oct 18 '19 at 16:34

1 Answers1

0

For your example you can do:

strr = "INDUSTRIAL, PARKS, PROPERTY"
','.join(strr.split(', '))

Otherwise if you have something like:

strr = "INDUSTRIAL, PARKS,    PROPERTY"
','.join([s.strip() for s in strr.split(', ')])
VnC
  • 1,936
  • 16
  • 26
  • thanks for the answer but how do I remove the ending space also? strr = "INDUSTRIAL, PARKS,PROPERTY " (note the ending space after Property) – xJokerx Oct 19 '19 at 03:49
  • use `.strip()` on the initial string – VnC Oct 19 '19 at 12:20