You can download this code by clicking the button below.
This code is now available for download.
This function accepts a list of numbers as input and returns two lists: one containing all the odd numbers from the list, and the other containing all the even numbers.
Technology Stack : Built-in libraries: list comprehension, isinstance, modulo operator
Code Type : Function
Code Difficulty : Intermediate
def get_odd_even_numbers(numbers):
if not isinstance(numbers, list):
raise ValueError("Input must be a list of numbers.")
odd_numbers = [num for num in numbers if num % 2 != 0]
even_numbers = [num for num in numbers if num % 2 == 0]
return odd_numbers, even_numbers