下面的代碼混淆了我:Python iter()函數如何工作?
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> zip(*([iter(a)]*2))
[(0, 1), (2, 3), (4, 5), (6, 7), (8, 9)]
>>> iter(a)
<listiterator object at 0x7f3e9920cf50>
>>> iter(a).next()
0
>>> iter(a).next()
0
>>> iter(a).next()
0
next()
總是返回0。那麼,如何在iter
功能工作?
密切相關:http://stackoverflow.com/q/29570348/2301450 – vaultah
@vaultah,我認爲它幾乎是一個確切的副本 –
@PadraicCunningham,對不起,我想知道如何*([iter(a) ] * 2)'工作,特別是Python中的'*'。 –