Python Practice › Loop Programs › Program 78
Copy special characters to a new list
Write a Python program to copy the special characters from a list into an empty list.
Input
["s", "2", "4", "6", "a", "@", "!", "%", "#"]
Output
['@', '!', '%', '#']
Approach
- Keep items that are not letters or digits.
Solution
a = ["s", "2", "4", "6", "a", "@", "!", "%", "#"]b = []for ch in a: if not ch.isalnum(): b.append(ch)print(b)Output
['@', '!', '%', '#']
Learn the concept
New to this topic? Read the lesson, then come back.