Copy special characters to a new list
Write a Python program to copy the special characters from a list into an empty list.
["s", "2", "4", "6", "a", "@", "!", "%", "#"]
['@', '!', '%', '#']
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)['@', '!', '%', '#']
Learn the concept
New to this topic? Read the lesson, then come back.