I’m new to Python. I am only 4 weeks into Uni learning Python so excuse my ignorance. Also, this is my first time here so excuse me if my question is thorough.
My instructions:
The
myMap
andmyFilter
functions expect a function of one argument and a list as arguments and return a list of the results.
My question:
When looking at my output, the only values that went through were the even numbers which is good but how do I alter the function to do the same for odd numbers without creating a different function.
My code:
# function argument for myFilter
def myFilterarg(num):
if num % 2 == 0:
return num
# myFilter function
def myFilter(myFilterarg, lyst):
result = []
for num in lyst:
result.append(myFilterarg(num))
for num in result:
if num is None:
result.pop()
return result
My output:
myFilter: [2, 4]
My reason why it failed:
Status: FAILED!
Check: 1
Test: The `myFilter` method returns a list of even numbers for [1, 2, 3, 4, 5].
Reason: `myFilter` returned an invalid value, expected [2, 4].
Error : AssertionError - Assertion failed: `myFilter` returned an invalid value, expected [2, 4].
Timestamp: 2024-06-10 06:46:35.504160
DaRk Pluto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.