Python loop for inside lambda

后端 未结 5 1303
夕颜
夕颜 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:04

    Just in case, if someone is looking for a similar problem...

    Most solutions given here are one line and are quite readable and simple. Just wanted to add one more that does not need the use of lambda(I am assuming that you are trying to use lambda just for the sake of making it a one line code). Instead, you can use a simple list comprehension.

    [print(i) for i in x]
    

    BTW, the return values will be a list on None s.

提交回复
热议问题