Python Forum
do_somenthing_with(x) for x in my_list if is_valid(x)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
do_somenthing_with(x) for x in my_list if is_valid(x)
#5
But that is what's happening. It's exactly the same as map/filter, if you consume all of the input at once:
>>> def do_something_with(x):
...   print(x**2)
...
>>> def is_valid(x):
...   return x % 2 == 0
...
>>> things = range(10)
>>> [do_something_with(x) for x in things if is_valid(x)]
0
4
16
36
64
[None, None, None, None, None]
>>> list(map(do_something_with, filter(is_valid, things)))
0
4
16
36
64
[None, None, None, None, None]
Reply


Messages In This Thread
RE: do_somenthing_with(x) for x in my_list if is_valid(x) - by nilamo - Sep-24-2018, 07:12 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020