Python loop for inside lambda

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

    To add on to chepner's answer for Python 3.0 you can alternatively do:

    x = lambda x: list(map(print, x))
    

    Of course this is only if you have the means of using Python > 3 in the future... Looks a bit cleaner in my opinion, but it also has a weird return value, but you're probably discarding it anyway.

    I'll just leave this here for reference.

提交回复
热议问题