Odd and Even numbers in a List

Python tutorial to get odd and even numbers from a list.
list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
list2 = []
list3 = []
for i in list1:
    if i % 2 != 0:
       list2.append(i)
    elif i % 2 == 0:
       list3.append(i)
print(list2)
print(list3)
#Output
[1, 3, 5, 7, 9]
[2, 4, 6, 8]

Leave a Reply