How to Remove All Numbers Values from List in Python?

By Hardik Savani October 30, 2023 Category : Python

Hey Dev,

Here, I will show you how to work how to remove all integer values from a list in python. I would like to show you python list remove integer values. you can see python list remove number values. you will learn how to remove number from list in python. Here, Create a basic example of how to extract number from list in python.

If you have list in python with numeric and string values in list and you want to remove integer values from list in python, then there are several ways to do that. i will give you simple two examples here using comprehension with isinstance() and isdigit() functions. so, let's see the following examples:

You can use these examples with python3 (Python 3) version.

let's see below a simple example with output:

Example 1:

main.py

# Create New List with Item
myList = ["a", 1, 2, "b", "c", 4, 5, "d"]
    
# Python list remove integer values
newList = [val for val in myList if isinstance(val, str)]
    
print(newList)

Output:

['a', 'b', 'c', 'd']

Example 2:

main.py

# Create New List with Item
myList = ["a", "1", "2", "b", "c", "4", "5", "d"]
  
# Python list remove integer values
newList = [val for val in myList if not val.isdigit()]
  
print(newList)

Output:

['a', 'b', 'c', 'd']

I hope it can help you...

Tags :
Shares