Created
October 23, 2019 23:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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