![]() |
VOOZH | about |
In this article, we will explore multiple approaches to find and print negative numbers in a list.
Example:
Input: lst = [12, -7, 5, 64, -14]
Output: -7, -14
List comprehension provides a compact way to filter negative numbers while keeping the code readable.
[-10, -5, -2]
Explanation:
The filter() function allows filtering elements based on a condition efficiently.
[-3, -1, -9]
Explanation:
A traditional for loop can be used to iterate through the list and print negative numbers directly.
-3 -1 -9
Explanation:
Using map() is less straightforward since it requires handling None values for non-negative numbers.
[-3, -1, -9]
Explanation: