Skip to content

Instantly share code, notes, and snippets.

@athursto
Created September 11, 2023 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save athursto/6651d37929c492ad9079585e3f75abc6 to your computer and use it in GitHub Desktop.
Save athursto/6651d37929c492ad9079585e3f75abc6 to your computer and use it in GitHub Desktop.
Casidoo 9.11.23
"""9.11.2023"""
"""This week's question: Given an array of integers, sort them into two separate sorted arrays of even and odd numbers.
If you see a zero, skip it."""
def separate_and_sort(array):
zeros_out = [num for num in array if num!= 0]
zeros_out.sort()
even_list, odd_list = [num for num in zeros_out if num % 2 == 0], [num for num in zeros_out if num % 2 != 0]
return even_list, odd_list
test_array_2 = [4,3,2,1,5,7,8,9]
print(separate_and_sort(test_array_2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment