I have a list of tags:
>>> tags_list
['tag1', 'second tag', 'third longer tag']
How can I replace whitespaces within each element of the list with "+" ? I was trying to do this with regular expressions but each string remains unchanged:
for tag in tags_list:
re.sub("\s+" , " ", tag)
What is wrong with my approach ?
EDIT:
Yes I forgot to mention, that between the words in each tag we can have multiple whitespaces as well as tags can begin or end with whitespaces, since they're parsed from a comma separated string with split(",") : ("First tag, second tag, third tag"). Sorry for not being precise enough.