Is it Pythonic to use list comprehensions for just side effects?

后端 未结 7 806
面向向阳花
面向向阳花 2020-11-21 06:23

Think about a function that I\'m calling for its side effects, not return values (like printing to screen, updating GUI, printing to a file, etc.).

def fun_wi         


        
7条回答
  •  萌比男神i
    2020-11-21 07:12

    You can do

    for z in (fun_with_side_effects(x) for x in y if (...conditions...)): pass
    

    but it's not very pretty.

提交回复
热议问题