
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python program to print odd 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 as input, we need to display odd numbers in the given iterable.
Here we will be discussing three different approaches to solve this problem.
Approach 1 − Using enhanced for loop
Example
list1 = [11,23,45,23,64,22,11,24] # iteration for num in list1: # check if num % 2 != 0: print(num, end = " ")
Output
11, 23, 45, 23, 11
Approach 2 − Using lambda & filter functions
Example
list1 = [11,23,45,23,64,22,11,24] # lambda exp. odd_no = list(filter(lambda x: (x % 2 != 0), list1)) print("Odd numbers in the list: ", odd_no)
Output
Odd numbers in the list: [11, 23, 45, 23, 11]
Approach 3 − Using the list comprehension
Example
list1 = [11,23,45,23,64,22,11,24] #list comprehension odd_nos = [num for num in list1 if num % 2 != 0] print("Odd numbers : ", odd_nos)
Output
Odd numbers in the list: [11, 23, 45, 23, 11]
Conclusion
In this article, we learned about the approach to find all odd numbers in the list given as input.
- Related Articles
- Python program to print all odd numbers in a range
- Python program to print even numbers in a list
- Python program to print negative numbers in a list
- Python program to Count Even and Odd numbers in a List
- Golang Program to Print Odd Numbers Within a Given Range
- Golang Program to Print the Largest Even and Largest Odd Number in a List
- Python program to print all even numbers in a range
- Python Program to Print Numbers in an Interval
- Python Program to print unique values from a list
- Python program to print all sublists of a list.
- Program to count number of valid pairs from a list of numbers, where pair sum is odd in Python
- Python Program to Find Element Occurring Odd Number of Times in a List
- Program to count odd numbers in an interval range using Python
- Program to find sum of first N odd numbers in Python
- Python program to print duplicates from a list of integers?

Advertisements