0
list1 = [10, 20, 25, 30, 35]
list2 = [40, 45, 60, 75, 90]
def is_odd(num,list1):
  for num in list1:
     if num % 2 != 0:
         print(num, end=" ")
def is_even(num,list2):
  for num in list2:
      if num % 2 == 0:
         print(num, end=" ") 
list3=[is_odd(num,list1)  or is_even(num,list2)]           
print(list3)

I get this output: 25 35 40 60 90 [None] I want to get result list: [25, 35, 40, 60, 90]

quamrana
  • 37,849
  • 12
  • 53
  • 71

1 Answers1

0

You are getting [None] because the print function returns None. Instead of printing, in the is_odd or is_even function, you should return the numbers and append it into list3.

def is_odd(list1):
  temp = []
  for num in list1:
     if num % 2 != 0:
         temp.append(num)
  return temp

def is_even(list2):
  temp = []
  for num in list2:
      if num % 2 == 0:
        temp.append(num)
  return temp

list1 = [10, 20, 25, 30, 35]
list2 = [40, 45, 60, 75, 90]
list3 = []
list3 += is_odd(list1)
list3 += is_even(list2)  
print(list3)
Leon
  • 31
  • 5