...

/

Remove Tabs in a String

Remove Tabs in a String

In this lesson, we will learn how to remove tabs from a string using recursion.

What does “Removing Tabs from a String” mean?

Our task is to remove all tabs from a string. This includes the character \t and " " from a string.

Removing spaces from a string
Removing spaces from a string

Implementation

Press + to interact
def remove(string):
# Base Case
if not string:
return ""
# Recursive Case
if string[0] == "\t" or string[0] == " ":
return remove(string[1:])
else:
return string[0] + remove(string[1:])
# Driver Code
print(remove("Hello\tWorld"))
...