Python Practice › List Programs › Program 19
Remove negative values
Write a Python program to remove negative values from a list.
Input
[4, -2, 0, 7, -9, 3]
Output
[4, 0, 7, 3]
Approach
- Keep values that are not below 0.
Solution
numbers = [4, -2, 0, 7, -9, 3]print([n for n in numbers if n >= 0])Output
[4, 0, 7, 3]
Learn the concept
New to this topic? Read the lesson, then come back.