Member-only story
Interview question: Remove special characters from a lower case string
It is important to know how to perform basic programming if one wants to become a Python developer.
One interview question that may crop up is how to remove special characters from a lower case string.
I have developed two ways that this question can be answered and will discuss them in this blog post.
The first method to remove special characters from a lower case string can be seen in the psuedocode below:-
- Define the variable, string, which is composed of alphabetical characters and special characters.
- Use Python’s lower function to convert the string to lower case.
- Define the variable, alpha_chars, which is all of the characters that can be included in the string.
- Define the variable, new_string, which is an empty string.
- Create a for loop where the variable, i, iterates through the elements of the variable, string. If i is in alpha_chars then add the value of i to the variable, new_string.
The code in python for this algorithm can be seen below:-
The second way to remove special characters from a lower case string is to use Python’s inbuilt re module. The re module is an acronym for regular…