下面的代码混淆了我: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中的'*'。 –