In this program, we will add special characters to an empty list.
Steps to solve the program
- Take a list as input.
- Create a list of special characters and create an empty list.
- Use for loop to iterate over input list.
- If the character from the input list is in the list of special characters then add it to the empty list.
- 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 :
['@', '!', '%', '#']