Remove white space without built-in function .strip() or others

hi guys, need help here.

I want to remove whitespace in a string without built-in function. I think about using a loop. Then I get stuck.
The logic is :

  1. loop the string
  2. if the string != ’ ':
  3. print string[i+1:]

This is the sample code:

string = ’ I love Aru ’

temp = ‘’
for i in range(len(string)):
if string[i] != ’ ':
temp = string[i+1:]

…it’s not finished

remove white spaces, how? All whitespaces so we get:


or remove all leading and trailing white spaces so we get:

'I love Aru'

Before we can solve a problem, we need clear requirements/understanding of the objective

Given we are going to mutate, I would go for a mutable data type (list) for the variable we use to store the result (temp variable)

1 Like