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)
#3
If you aren't trying to generate a list (or whatever sequence) then it is absolutely NOT more pythonic to use a comprehension. Using a comprehension for a side effect is an anti-pattern.

For example, the following is an example of what NOT to do:
[print(x) for x in range(10)]
You aren't actually interested in the list you create, and are abusing comprehension syntax (which is completely unnecessary).

So, do you actually want the list or do you just want a function to run several times with different inputs?
Reply


Messages In This Thread
RE: do_somenthing_with(x) for x in my_list if is_valid(x) - by Mekire - Sep-23-2018, 11:35 AM

Forum Jump:

User Panel Messages

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