How to Pythonically yield all values from a list?

后端 未结 4 1089
青春惊慌失措
青春惊慌失措 2020-12-16 08:46

Suppose I have a list that I wish not to return but to yield values from. What is the most pythonic way to do that?

Here is what I mean. Thanks to some non-lazy comp

4条回答
  •  太阳男子
    2020-12-16 09:41

    Use iter to create a list iterator e.g.

    return iter(List)
    

    though if you already have a list, you can just return that, which will be more efficient.

提交回复
热议问题