Python Practice › Loop Programs › Program 77
Copy odd numbers to a new list
Write a Python program to copy the odd numbers from a list into an empty list.
Input
[3, 8, 5, 0, 2, 7]
Output
[3, 5, 7]
Approach
- Append numbers with remainder 1.
Solution
a = [3, 8, 5, 0, 2, 7]b = [n for n in a if n % 2 == 1]print(b)Output
[3, 5, 7]
Learn the concept
New to this topic? Read the lesson, then come back.