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)
#1
It would be nice if python supported this kind of "expression comprehension", or do it?

I frecuently encounter situations in which I need to execute some function for a list of things, or a range of whatever, and wonder if it could be done in a one-liner like the message title. I know we have map's, and for's but I think this feels more natural and "pythonic"

Is there a syntax I'm not aware of? Or maybe someone proposed this in the past but coulnd't be done for any unwanted effects?
Reply


Messages In This Thread
do_somenthing_with(x) for x in my_list if is_valid(x) - by pystag - Sep-23-2018, 09:58 AM

Forum Jump:

User Panel Messages

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