-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update the-filter-built-in-function.md #2617
base: master
Are you sure you want to change the base?
Update the-filter-built-in-function.md #2617
Conversation
I have updated this question because when I test the code, the output was: <filter object at 0x0000012E54DF0EE0> Instead of: [-3,-2,-1] So I modified the example a little bit by adding a for loop to print out the filtered results.
This comment has been minimized.
This comment has been minimized.
@@ -104,15 +104,26 @@ What is the printed result of the following code execution? | |||
numbers = [-3, -2, -1, 0, 1, 2, 3] | |||
def mystery_function(element): | |||
return element < 0 | |||
print(filter(mystery_function, numbers)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could have just converted the filter object to list,
filtered = filter(mystery_function, numbers)
print(list(filtered))
I think, this approach is straightforward instead of the for loop..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
I have updated this question because when testing the code, the output was:
<filter object at 0x0000012E54DF0EE0>
Instead of:
[-3,-2,-1]
I modified the example a little bit by saving the filtered result in a new variable and then printing the filtered result using a for loop.