Skip to content

Instantly share code, notes, and snippets.

@elsheikh21
Created October 23, 2019 23:03
Show Gist options
  • Save elsheikh21/92564b975963423beff806add8381322 to your computer and use it in GitHub Desktop.
Save elsheikh21/92564b975963423beff806add8381322 to your computer and use it in GitHub Desktop.
filter odd & even from a given a list, and return a list of 2 lists
def filter(array):
odd_numbers, even_numbers = [], []
for num in array:
if num % 2 == 0:
even_numbers.append(num)
else:
odd_numbers.append(num)
return [even_numbers, odd_numbers]
array = [4, 1, 8, 5, 10, 3, 9]
print(filter(array))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment