Create two lists from one list of number in Python
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways
Answers ( 3 )
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)
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)
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]