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)
#6
(Sep-24-2018, 07:05 AM)pystag Wrote: Obviously, the point here isn't to make a list (which is trivial), but to be able to execute commands in a "comprehension fashion".
And that is exactly my point. You shouldn't be using a comprehension. Yes, you can write a comprehension that does exactly what you want, but it isn't encouraged. If you care about being "pythonic" write a standard for loop and use multiple lines. If you don't care, knock-yourself out and shove it all into a one line list comp.
Reply


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

Forum Jump:

User Panel Messages

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