0
276views
Create a new list such that new list should contain only odd no from 1st list and even no from 2nd list.

Given a 2 list of no’s create a new list such that new list should contain only odd no’s from 1st list and even no’s from 2nd list.

1 Answer
0
5views

Create 2 list and add some values to the list & create an one empty list.

Iterate over the 1st list and if the element is odd then append to the empty list.

Iterate over the 2nd list and if the element is even then append to the empty list.

   List1=[1,2,3,4,5,6]
    List2=[7,8,9,10,11,12]
    New_list=[]
    for n in List1:
        if(n%2!=0):
           New_list.append(n)
    for n in List2:
        if(n%2==0):
           New_list.append(n)
    print("Odd no's from 1st list and Even no's from 2nd list",New_list)

Output

enter image description here

Please log in to add an answer.