看板 Python 關於我們 聯絡資訊
請問一行python code 版本是2.7 start = (n for n, e in graph.iteritems() if len(e) == 1).next() ^^^^^^ graph是一個dictionary type的object 請問後面的.next()的用途是什麼呢? 我有上網查了文件一下 他寫 Retrieve the next item from the iterator by calling its next() method. If default is given, it is returned if the iterator is exhausted, otherwise StopIteration is raised. 小弟我看不太懂 >"< 把next()拿掉也會出錯 有請好心人幫我解惑了...感恩 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 1.172.61.182
ccwang002:(...) 內是 generator, (...).next() 回傳第一個值 11/13 19:50
ccwang002:Ex. g = (x for x in [1, 2]); g.next() # 1 11/13 19:50
tainanyes:樓上謝謝~~我大概了解了! 11/13 20:35