Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Remove All Elements Less Than 10 from a List

Python Remove All Elements Less Than 10 from a List

Document Object Reference Manual Python3 Examples

In Python, we can use a list comprehension to filter out all elements less than 10 from a list. A list comprehension is a concise way to create a new list by iterating over the original list and applying a condition to select elements.

Example

original_list

=

[

5

,

12

,

3

,

18

,

7

,

20

]

filtered_list

=

[

x

for

x

in

original_list

if

x

=

10

]

print

(

filtered_list

)

Code analysis:

Output result:

Example

[

12

,

18

,

20

]

Document Object Reference Manual Python3 Examples