Python Practice › List Programs › Program 19

Remove negative values

EasyList Programs · 19 of 100

Write a Python program to remove negative values from a list.

Advertisement
Input
[4, -2, 0, 7, -9, 3]
Output
[4, 0, 7, 3]

Approach

  1. Keep values that are not below 0.

Solution

Python
numbers = [4, -2, 0, 7, -9, 3]print([n for n in numbers if n >= 0])
Output
[4, 0, 7, 3]
Advertisement

Learn the concept

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

More list programs

← All 100 List Programs