Python loop for inside lambda

后端 未结 5 1281
夕颜
夕颜 2020-12-15 04:47

In my code I need to simplify as much as possible my line of code. EDIT: I think I\'m not clear enough - it needs to be one line of code. I need to put a for loop inside a l

5条回答
  •  庸人自扰
    2020-12-15 05:02

    Since a for loop is a statement (as is print, in Python 2.x), you cannot include it in a lambda expression. Instead, you need to use the write method on sys.stdout along with the join method.

    x = lambda x: sys.stdout.write("\n".join(x) + "\n")
    

提交回复
热议问题