Python Practice › Loop Programs › Program 78

Copy special characters to a new list

EasyLoop Programs · 78 of 90

Write a Python program to copy the special characters from a list into an empty list.

Advertisement
Input
["s", "2", "4", "6", "a", "@", "!", "%", "#"]
Output
['@', '!', '%', '#']

Approach

  1. Keep items that are not letters or digits.

Solution

Python
a = ["s", "2", "4", "6", "a", "@", "!", "%", "#"]b = []for ch in a:    if not ch.isalnum():        b.append(ch)print(b)
Output
['@', '!', '%', '#']
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More loop programs

← All 90 Loop Programs