Thursday, September 4, 2025
HomeLanguagesRemove all Alphanumeric Elements from the List – Python

Remove all Alphanumeric Elements from the List – Python

Alphanumeric elements consist of only alphabetical and numerical characters. Any of the special characters are not included in alphanumeric elements.

This article is going to show you multiple ways to remove all the alphanumeric elements from a List of strings using Python.

Example 1:
Input: ['a','b', '!', '1', '2', '@', 'abc@xyz.com']
Output: ['!', '@', 'abc@xyz.com']

Example 2:
Input: ['A+B', '()', '50', 'xyz', '-', '/', '_', 'pq95', '65B']
Output: ['A+B', '()', '-', '/', '_']

How to Remove all Alphanumeric Elements from the List in Python using isalnum()

isalnum() is a Python string method that returns True If all the characters are alphanumeric.

Python3




l1 = ['A+B', '()', '50', 'xyz', '-', '/', '_', 'pq95', '65B']
l2 = list()
  
for word in l1:
   if not word.isalnum():
        l2.append(word)
  
print(l2)


Output:

['A+B', '()', '-', '/', '_']

Time Complexity: O(N)
Auxiliary Space: O(N)

How to Remove all Alphanumeric Elements from the List in Python using isalpha() and isnumeric()

isalpha() is a Python string method that returns True if all characters are alphabets.

isnumeric() is a Python string method that returns True if all characters are numbers.

Python3




l1 = ['A+B', '()', '50', 'xyz', '-', '/', '_', 'pq95', '65B']
l2 = list()
  
for word in l1:
   for char in word:
       if not (char.isalpha() or char.isnumeric()):
           l2.append(word)
           break
  
print(l2)


Output:

['A+B', '()', '-', '/', '_']

Time Complexity: O(N)
Auxiliary Space: O(N)

How to Remove all Alphanumeric Elements from the List in Python using ASCII Value or Range

ASCII  stands for American Standard Code for Information Interchange is a common data encoding format for data communication. According to this standard every letter, number, and special character has associated ASCII values.

Python3




l1 = ['A+B', '()', '50', 'xyz', '-', '/', '_', 'pq95', '65B']
l2 = list()
  
for word in l1:
   for char in word:
       if not ((char >= 'A' and char <= 'Z'
               or 
               (char >= 'a' and char <= 'z')
               or
               (char >= '0' and char <= '9')):
           l2.append(word)
           break
  
print(l2)


Output:

['A+B', '()', '-', '/', '_']

Time Complexity: O(N)
Auxiliary Space: O(N)

How to Remove all Alphanumeric Elements from the List in Python using Regular Expression

Regular Expression or RegEx is a tool useful for pattern-based string matching. The python standard library already provides a re module for using RegEx in Python easily and effectively.

Python3




import re
  
l1 = ['A+B', '()', '50', 'xyz', '-',
      '/', '_', 'pq95', '65B']
l2 = list()
  
for s in l1:
  if re.findall(r'''[]_`~!@#$%^&*()-+={[}}|\:;"'<,>.?/]''',s):
    l2.append(s)
print(l2)


Output:

['A+B', '()', '-', '/', '_']

Time Complexity: O(N)
Auxiliary Space: O(N)

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32263 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6627 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11858 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6696 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS