Menu Close

Split elements into even and odd list

Python Program to Put Even and Odd elements in a List into Two Different Lists

Input
First Line is the Number of Inputs
Second line is the elements of the list

Output
Print the Even List and Odd List

N=int(input('Enter the N value: '))
l1=[]
print('Enter the elements for the list:  ')
for i in range(N):
  l1.append(int(input('')))


print('The even list',list(filter(lambda x: (x%2==0),l1)))
print('The odd list',list(filter(lambda x: (x%2!=0),l1)))

Input_1:
Enter the N value: 5
Enter the elements for the list:
67
43
44
22
455
Output:
The even list [44, 22]
The odd list [67, 43, 455]


Input_2:
Enter the N value: 7
Enter the elements for the list:
70
10
25
17
84
28
62
Output:
The even list [70, 10, 84, 28, 62]
The odd list [25, 17]


Morae Q!