Python Practice › Loop Programs › Program 77

Copy odd numbers to a new list

EasyLoop Programs · 77 of 90

Write a Python program to copy the odd numbers from a list into an empty list.

Advertisement
Input
[3, 8, 5, 0, 2, 7]
Output
[3, 5, 7]

Approach

  1. Append numbers with remainder 1.

Solution

Python
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.

More loop programs

← All 90 Loop Programs

Leave a Comment