Add special characters in an empty list

In this program, we will add special characters to an empty list.

Steps to solve the program
  1. Take a list as input.
  2. Create a list of special characters and create an empty list.
  3. Use for loop to iterate over input list.
  4. If the character from the input list is in the list of special characters then add it to the empty list.
  5. Print the output.
				
					list1 = ["s",2,4,6,"a","@","!","%","#"]
special_char = ["!","@","#","$","%","^","}"
               ,"&","*","(",")","{","[","]"]
list2 = []

for char in list1:
    if char in special_char:
        list2.append(char)
        
print(list2)
				
			

Output :

				
					['@', '!', '%', '#']
				
			

add odd numbers in an empty list from a given list

print the last element of a list using a while loop

Leave a Comment