Why doesn’t .strip() remove whitespaces? [duplicate]

strip does not remove whitespace everywhere, only at the beginning and end. Try this:

def solve_eq(string1):
    return string1.replace(' ', '')

This can also be achieved using regex:

import re

a_string = re.sub(' +', '', a_string)

Leave a Comment