Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Stefan-Stojanovic
Copy link
Collaborator

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.

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.
@enki-hq

This comment has been minimized.

@enki-hq
Copy link
Collaborator

enki-hq commented Feb 9, 2021

@@ -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))
Copy link
Contributor

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..

Copy link
Contributor

@mukeshgurpude mukeshgurpude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 38 of it's mentioned as follows

filter always returns a list, unless the iterable object passed in is a string or a tuple

For me on python3.9, filter is returning the filter object, so, I think this line should be rewritten.
image

mukeshgurpude
mukeshgurpude previously approved these changes Apr 23, 2021
Copy link
Contributor

@mukeshgurpude mukeshgurpude left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants