In this program, we will take a string as input and remove all characters except the given character in a string.
Steps to solve the program
- Take a string as input.
- Remove all characters except the given character and add them to the list using list comprehension.
- Use for loop to iterate over each character of the string.
- Print the output.
#Input string
str1 = "Sqatools python"
#Printing output
print(''.join([el for el in str1 if el == "S"]))
Output :
S