Last modified: Aug 12, 2026

Remove Integers from Python List

Working with lists is common in Python. Sometimes you need to clean your data. You might want to remove all integer values from a list. This is a typical task for data cleaning.

In this guide, you will learn simple methods. We will use list comprehension, the filter() function, and loops. Each method is clear and easy to follow. We will also show code examples and outputs.

Let's start with the most popular and readable method. You will see how to keep only non-integer items. This helps when you mix numbers and strings.

Why Remove Integers from a List?

Lists often hold mixed data types. You might have a list with numbers and text. For analysis, you may need only text. Or you may want to remove specific numeric values. Removing integers makes your data consistent.

For example, a list like [10, 'apple', 5, 'banana', 3.14]. Here, 10 and 5 are integers. You want to keep strings and floats. This is a common need in data preprocessing.

Python offers several ways to achieve this. We will explore the best ones. Each approach has its strengths. Choose the one that fits your style.

Method 1: Using List Comprehension

List comprehension is the cleanest way. It creates a new list in one line. You can check each item with isinstance(). This function checks the type of an object.


# Original list with mixed types
mixed_list = [10, 'apple', 5, 'banana', 3.14, 7, 'cherry']

# Remove all integers using list comprehension
filtered_list = [item for item in mixed_list if not isinstance(item, int)]

print("Original list:", mixed_list)
print("Filtered list:", filtered_list)

Original list: [10, 'apple', 5, 'banana', 3.14, 7, 'cherry']
Filtered list: ['apple', 'banana', 3.14, 'cherry']

This method is fast and readable. The condition not isinstance(item, int) keeps non-integers. It works for both positive and negative integers. Remember, booleans are a subtype of int in Python. So True and False will also be removed. If you want to keep them, use a stricter check.

You can also remove only specific integers. For instance, remove all numbers less than 10. But the basic method above is perfect for general removal.

Method 2: Using the filter() Function

The filter() function is another elegant way. It takes a function and an iterable. It returns an iterator with the filtered items. You can convert the result to a list.

This method is functional and concise. It is great when you already have a function. Let's see it in action.


# Original list
mixed_list = [1, 'hello', 2, 'world', 3.5, 4, 'python']

# Function to check if item is not an integer
def is_not_int(x):
    return not isinstance(x, int)

# Use filter to remove integers
filtered_list = list(filter(is_not_int, mixed_list))

print("Original list:", mixed_list)
print("Filtered list:", filtered_list)

Original list: [1, 'hello', 2, 'world', 3.5, 4, 'python']
Filtered list: ['hello', 'world', 3.5, 'python']

You can also use a lambda function. This makes the code shorter. However, for readability, a named function is better. The filter() method is efficient for large lists. It performs well because it processes items lazily.

If you need to remove integers from a list and also perform other operations, this method is flexible. You can combine it with other functions easily.

Method 3: Using a For Loop

Sometimes a simple loop is the most understandable. This is especially true for beginners. You can iterate through the list and build a new one. It gives you full control over the logic.

Here is how to use a for loop. We will create an empty list and append non-integer items.


# Original list
mixed_list = [10, 'cat', 20, 'dog', 30.5, 40, 'bird']

# Create an empty list for results
filtered_list = []

# Loop through each item
for item in mixed_list:
    if not isinstance(item, int):
        filtered_list.append(item)

print("Original list:", mixed_list)
print("Filtered list:", filtered_list)

Original list: [10, 'cat', 20, 'dog', 30.5, 40, 'bird']
Filtered list: ['cat', 'dog', 30.5, 'bird']

This method is explicit. You can easily add more conditions. For example, you might want to skip strings that start with a vowel. The loop allows for complex logic.

It is also a good way to understand the process. You see each item being checked. This is helpful for learning. However, it is more verbose than list comprehension. But it is still a valid and clear approach.

Remember to use isinstance() instead of type(). The type() function has issues with subclasses. isinstance() is more robust and recommended.

Method 4: Removing Integers In-Place

All previous methods create a new list. If you want to modify the original list, you can remove items in-place. This uses a while loop. It is efficient when you have a large list and want to save memory.

Here is an example. We iterate backwards to avoid index shifting issues.


# Original list
my_list = [1, 'a', 2, 'b', 3, 'c', 4]

# Iterate backwards using a while loop
i = len(my_list) - 1
while i >= 0:
    if isinstance(my_list[i], int):
        del my_list[i]
    i -= 1

print("Modified list:", my_list)

Modified list: ['a', 'b', 'c']

Using del removes the element. This is a direct way to modify the list. It is useful when you don't need the original data. But be careful with large lists, as deleting elements can be slow.

If you prefer, you can also use a list comprehension and assign it back. But that creates a new list anyway. The in-place method is memory-efficient. For more details on the del statement, check our guide on Python List del: Remove Items Easily.

Handling Edge Cases

When removing integers, consider edge cases. Booleans are considered integers in Python. So True and False will be removed. If you want to keep them, check for type(item) is int instead. But this is less flexible.

Also, consider floats. Floats are not integers. So they will be kept. If you want to remove all numbers, you need to check for both int and float. This is a common requirement.


# Remove both int and float
mixed = [1, 2.5, 'x', 3, 'y', 4.0]
result = [item for item in mixed if not isinstance(item, (int, float))]
print(result)  # Output: ['x', 'y']

This shows how to extend the condition. You can remove any numeric type. This is useful for text-only lists. If you are working with mixed data, this is a powerful trick.

Another edge case is a list with nested lists. The isinstance() check will see the inner list as a list, not an integer. So it will be kept. This is usually what you want. But be aware of the structure.

Performance Considerations

List comprehension is generally the fastest. It is optimized in C. The filter() function is also fast, but it returns an iterator. Converting to a list adds a small overhead.

For loops are slower but more readable. For large lists, list comprehension is the best choice. It is both fast and concise. If you are processing millions of items, use list comprehension.

In-place removal with del can be slow for large lists. This is because shifting elements takes time. But it saves memory. Choose based on your needs.

For most cases, list comprehension is the recommended approach. It balances readability and performance. You can also use it with complex conditions. This makes it very versatile.

Related Techniques

Removing integers is similar to other list operations. For example, you might want to remove specific values. You can use remove() or pop(). But those remove by value or index, not by type.

If you need to remove items by index, check our article on Python List Remove by Index. This is useful when you know the position. For removing NaN values, which are floats, see Remove NaN from Python List. These guides complement your learning.

Also, understanding list length and counting is helpful. You can check how many integers remain. See Python List Count: Easy Guide for counting occurrences. These techniques work together well.

Conclusion

Removing integers from a list is a simple task. You have learned four effective methods. List comprehension is the most elegant. The filter() function is functional and clean. A for loop is beginner-friendly. In-place removal saves memory.

Each method has its use case. Choose the one that fits your project. Always test with your data. Remember to handle booleans and floats as needed. With these tools, you can clean any list easily.

Practice with your own examples. Try to remove only negative integers or numbers above a threshold. The key is to understand isinstance(). Once you master this, you can filter any list with confidence.