Create two lists from one list of number in Python

Question

List_1 = [1,4,3,5,3,2,6]

Output
even = [4,2,6]
Odd = [1,3,5,3]

in progress 0
TheDataMonk 3 years 3 Answers 639 views Grand Master 0

Answers ( 3 )

  1. even_list=[]
    odd_list=[]
    for i in range(0,len(List_1)):
    if List_1[i]%2 == 0:
    even_list.append(List_1[i])
    else:
    odd_list.append(List_1[i])
    print(even_list)
    print(odd_list)

  2. List_1 = [1,4,3,5,3,2,6]
    odd=[]
    even=[]

    for i in range(len(List_1)):
    if i%2==0:
    even.append(i)
    else:
    odd.append(i)
    print(odd)
    print(even)

  3. List_1 = [1,4,3,5,3,2,6]

    def list_split(x):
    even=[]
    odd=[]
    for i in x:
    if i % 2==0:
    even.append(i)
    else:
    odd.append(i)
    print(even)
    print(odd)
    list_split(List_1)

    OUTPUT:
    [4, 2, 6]
    [1, 3, 5, 3]

Leave an answer

Browse
Browse