On Fri, Feb 12, 2021 at 1:01 AM Henry Harutyunyan <henryharutyun...@gmail.com> wrote: > this is fine as long as you need to use that filter for once. But if you want > to reuse it you either need to create the iterator every time specifying the > filter function, or save the function in a var and create the filter with > that. > > I'm wondering why can't we create custom filters and mappers that are > reusable. The result will look something like this: > > ``` > >>> pass_filter = filter(lambda x: x > 60) > >>> foo = [42, 56, 67, 87] > >>> for i in pass_filter(foo): > >>> print(i) > 67 > 86 > >>> bar = {45, 94, 65, 3} > >>> for i in pass_filter(bar): > >>> print(i) > 65 > 94 > ``` > Are there any drawbacks or limitations to this? Is is worth working on?
Why not simply define your function and give it a name? def above_sixty(x): return x > 60 That'd give you most of the same benefits. Making filter/map do something completely different if you omit an argument is a bug magnet. ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/HQHH4BFOIKW2AZLHCIIAAXUCP7YACDPQ/ Code of Conduct: http://python.org/psf/codeofconduct/