How to Pythonically yield all values from a list?

后端 未结 4 1055
青春惊慌失措
青春惊慌失措 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:37

    Best Pythonically way to do this task is

    In [1]: my_list = ['a', 'b', 'c', 'd']
    
    In [2]: (x for x in my_list)
    Out[2]:  at 0x7fd9e4fdc230>
    

提交回复
热议问题