Remove unwanted characters from the given string

In this program, we will take a string as input and remove unwanted characters from the given string.

Steps to solve the program
  1. Take a string as input.
  2. Remove the unwanted characters using isalnum() and for loop.
  3. Print the output.
				
					#Input string
string1="Prog^ra*m#ming"
test_str = ''.join(letter for letter in string1 if letter.isalnum())
#Printing output
print(test_str)

#Input string
string2="Py(th)#@&on Pro$*#gram"
test_str = "".join(letter for letter in string2 if letter.isalnum())
#Printing output
print(test_str)
				
			

Output :

				
					Programming

Programming PythonProgram
				
			

remove duplicate words from the string.

find the longest capital letter word from the string.

Leave a Comment