1
我試圖從Python 3中獲得一組蛇的結果(從左到右,自上而下)。 我已經成功地使用zip,下面是一些示例代碼:蛇導致Python
>>> abcd = ['a','b','c','d']
>>> i = iter(abcd)
>>> t = zip(i,i)
>>> for x in t:
... print(x)
...
('a', 'b')
('c', 'd')
>>> for g in zip(abcd,abcd):
... print(g)
...
('a', 'a')
('b', 'b')
('c', 'c')
('d', 'd')
但我想明白爲什麼拉鍊(ABCD,ABCD)不返回相同的結果拉鍊(我,我)?
我假定zip採用可迭代列表,而不是迭代器作爲參數,至少這是我從定義中理解的, def zip(* iterables) – alortimor