I have a list, where each element of the list is the title of a chapter. Each title is formatted in the following way: '[Series name] [chapter number] : [chapter title]' So, an excerpt of my list would be
chapter_title:['One Piece 1 : Romance Dawn', 'One Piece 2 : They Call Him Strawhat Luffy', 'One Piece 3 : Pirate Hunter Zoro Enters']
I want to remove the space between the chapter number and the colon. My working code was:
no_space_regex = re.compile(r'\s:')
for i in chapter_title:
no_space_regex.sub(':',i)
However, it didn't make the substitution. Moreover, I know the compile works, because if I use re.findall it finds all the whitespaces followed by a colon.
I kinda solved it, using:
no_space_regex = re.compile(r'\s:')
def_chapter=[] #list of chapter titles with no space before :
for i in chapter_title:
i = no_space_regex.sub(':',i)
def_chapter.append(i)
but I was wondering why re.sub did not substitute it in place, like it is supposed to.