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

后端 未结 7 805
面向向阳花
面向向阳花 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条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-21 06:54

    It is very anti-Pythonic to do so, and any seasoned Pythonista will give you hell over it. The intermediate list is thrown away after it is created, and it could potentially be very, very large, and therefore expensive to create.

提交回复
热议问题