This blog contain program that finds out even number from first list and stored all even elements into a new list
Create a number list
num = [1,2,3,4,5,6,7,8,9,0]
Create a empty list which will store all even elements
even_num = []
Use for loop to access each element from first list and checking whether the current element is even or odd using modulus operator. Appending even element in second list
for n in num:
if n%2 == 0:
even_num.append(n)
Printing both lists
print('Original Array: ',num)
print('Only even values: ',even_num)
Output
Original Array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] Only even values: [2, 4, 6, 8, 0]
Complete Code
num = [1,2,3,4,5,6,7,8,9,0] even_num = [] for n in num: if n%2 == 0: even_num.append(n) print('Original Array: ',num) print('Only even values: ',even_num)