- 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

# Program to find sum of odd elements from list in Python

Suppose we have a list of n elements called nums. We have to find sum of all odd elements from the list.

So, if the input is like nums = [5,7,6,4,6,9,3,6,2], then the output will be 24 because 5+7+9+3 = 24.

To solve this, we will follow these steps −

- Solve this by list comprehension also
- l := a list of elements e for all e in nums and when e is odd
- return the sum of elements in l by passing l into sum() function.

## Example

Let us see the following implementation to get better understanding −

def solve(nums): return sum([i for i in nums if i % 2 == 1]) nums = [5,7,6,4,6,9,3,6,2] print(solve(nums))

## Input

[5,7,6,4,6,9,3,6,2]

## Output

24

- Related Questions & Answers
- Python program to find sum of elements in list
- Find sum of elements in list in Python program
- Program to find maximum sum of popped k elements from a list of stacks in Python
- Program to find sum of all odd length subarrays in Python
- Program to find sum of first N odd numbers in Python
- Program to find largest sum of non-adjacent elements of a list in Python
- Program to find duplicate item from a list of elements in Python
- Program to find sum of unique elements in Python
- Python program to find the sum of all even and odd digits of an integer list
- Program to find three unique elements from list whose sum is closest to k Python
- Program to find sum of non-adjacent elements in a circular list in python
- Python program to find N largest elements from a list
- Program to find the sum of first n odd numbers in Python
- Program to find number of elements can be removed to make odd and even indexed elements sum equal in Python
- Python Program for Find sum of odd factors of a number

Advertisements