

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to print negative numbers in a list
In this article, we will learn about the solution and approach to solve the given problem statement.
Problem statement
Given a list iterable, we need to print all the negative numbers in the list.
Here we will be discussing three approaches for the given problem statement.
Approach 1 − Using enhanced for loop
Example
list1 = [-11,23,-45,23,-64,-22,-11,24] # iteration for num in list1: # check if num < 0: print(num, end = " ")
Output
-11 -45 -64 -22 -11
Approach 2 − Using filter & lambda function
Example
list1 = [-11,23,-45,23,-64,-22,-11,24] # lambda exp. no = list(filter(lambda x: (x < 0), list1)) print("Negative numbers in the list: ", no)
Output
Negative numbers in the list: [-11 -45 -64 -22 -11]
Approach 3 − Using list comprehension
Example
list1 = [-11,23,-45,23,-64,-22,-11,24] #list comprehension nos = [num for num in list1 if num < 0] print("Negative numbers in the list: ", nos)
Output
Negative numbers in the list: [-11 -45 -64 -22 -11]
Conclusion
In this article, we learned about the approach to print negative numbers in the input list.
- Related Questions & Answers
- Python program to count positive and negative numbers in a list
- Python program to print even numbers in a list
- Python program to print odd numbers in a list
- Golang Program to Print the Sum of all the Positive Numbers and Negative Numbers in a List
- Count positive and negative numbers in a list in Python program
- Python program to print all even numbers in a range
- Python program to print all odd numbers in a range
- Python Program to Print Numbers in an Interval
- Lambda expression in Python Program to rearrange positive and negative numbers
- Python program to print all sublists of a list.
- Python Program to print unique values from a list
- Print a list in Python
- Python program to print duplicates from a list of integers?
- Negative Binary Numbers
- Python program to print all Prime numbers in an Interval
Advertisements