2017-01-07 19 views

回答

2

這是一個辦法做到這一點使用mapdeque消耗迭代器(解釋一下:itertools consume recipie) :

from collections import deque 

def my_gen(): 
    data = '' 
    while data is not None: 
     print(data) 
     data = yield data 
    print(data) 
    yield data 

lst = [1, 2, 3] 
it = my_gen() 
next(it) # priming the generator still needs to be done 

deque(map(it.send, lst), maxlen=0) 
+0

對不起,誤會。更新了問題。這不是關於發送數據的性質,而是關於如果我們可以在標準函數中「進行」(也許是啓動)? – VladimirLenin

相關問題