久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

了解 zip 功能

understanding zip function(了解 zip 功能)
本文介紹了了解 zip 功能的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

所有討論都是關于 python 3.1.2;有關我的問題的來源,請參閱 Python 文檔.

All discussion is about python 3.1.2; see Python docs for the source of my question.

我知道 zip 是做什么的;我只是不明白為什么可以這樣實現:

I know what zip does; I just don't understand why it can be implemented like this:

def zip(*iterables):
    # zip('ABCD', 'xy') --> Ax By
    iterables = map(iter, iterables)
    while iterables:
        yield tuple(map(next, iterables))

假設我調用 zip(c1, c2, c3).如果我理解正確的話,iterables 最初是元組 (c1, c2, c3).

Let's say I call zip(c1, c2, c3). If I understand correctly, iterables is initially the tuple (c1, c2, c3).

iterables = map(iter, iterables) 行將其轉換為迭代器,如果迭代則返回 iter(c1)、iter(c2)、iter(c3).

The line iterables = map(iter, iterables) converts it to an iterator that would return iter(c1), iter(c2), iter(c3) if iterated through.

在循環內部,map(next, iterables) 是一個迭代器,它會返回 next(iter(c1)), next(iter(c2))next(iter(c3))(如果迭代).tuple 調用將其轉換為 (next(iter(c1)), next(iter(c2)), next(iter(c3)),用盡其參數 (iterables) 在第一次調用時,據我所知.我不明白 while 循環如何設法繼續,因為它檢查 iterables; 如果它確實繼續為什么 tuple 調用不返回空元組(迭代器被耗盡).

Inside the loop, map(next, iterables) is an iterator that would return next(iter(c1)), next(iter(c2)), and next(iter(c3)) if iterated through. The tuple call converts it to (next(iter(c1)), next(iter(c2)), next(iter(c3)), exhausting its argument (iterables) on the very first call as far as I can tell. I don't understand how the while loop manages to continue given that it checks iterables; and if it does continue why the tuple call doesn't return empty tuple (the iterator being exhausted).

我確定我錯過了一些非常簡單的東西..

I'm sure I'm missing something very simple..

推薦答案

看起來這是文檔中的一個錯誤.等效"代碼在 python2 中有效,但在 python3 中無效,進入無限循環.

It looks like it's a bug in the documentation. The 'equivalent' code works in python2 but not in python3, where it goes into an infinite loop.

而且最新版本的文檔也有同樣的問題:http://docs.python.org/release/3.1.2/library/functions.html

And the latest version of the documentation has the same problem: http://docs.python.org/release/3.1.2/library/functions.html

看起來更改 61361 是問題,因為它合并了從 python 2.6 更改,但未驗證它們是否適用于 python3.

Looks like change 61361 was the problem, as it merged changes from python 2.6 without verifying that they were correct for python3.

看起來該問題在主干文檔集中不存在,但您可能應該在 http://bugs.python.org/.

It looks like the issue doesn't exist on the trunk documentation set, but you probably should report a bug about it at http://bugs.python.org/.

這篇關于了解 zip 功能的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時出現問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節點)
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應并將元素值存儲在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對象)
主站蜘蛛池模板: 羞羞视频在线免费 | 伊人在线 | 国产在线观看 | 美女久久 | 久久久久国产精品免费免费搜索 | 涩涩99 | 99re| 一区二区高清在线观看 | 国产黄色小视频在线观看 | 久久精品国产亚洲一区二区三区 | 国产视频久久 | 午夜精品 | 日韩一二区 | 欧美激情精品久久久久久 | 久久国产视频网站 | 国产亚洲欧美日韩精品一区二区三区 | 成人做爰www免费看 午夜精品久久久久久久久久久久 | 在线免费观看成年人视频 | 欧美色综合天天久久综合精品 | 超碰97av | 久久精品高清视频 | 男女羞羞视频在线看 | 综合网中文字幕 | 国产乱性 | 久久亚洲天堂 | 国产精品精品视频一区二区三区 | 日韩精品无码一区二区三区 | 国产高清精品一区二区三区 | 日韩毛片在线观看 | 日日碰狠狠躁久久躁婷婷 | 国产91综合一区在线观看 | 天天av综合 | 国产亚洲第一页 | cao视频| 国产精品一二三区 | 久久久久久久一区 | 神马久久久久久久久久 | 亚洲午夜av久久乱码 | 国产综合精品一区二区三区 | 波多野结衣二区 | 国产1区2区3区|