久久久久久久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 對象)
主站蜘蛛池模板: 欧洲精品一区二区 | 日韩av在线影院 | 一区二区免费看 | 黄色片网站在线观看 | 久久久久久久久国产 | 四虎成人在线 | 午夜精品在线观看 | 久久久久一 | 四虎黄色片 | 国产这里只有精品 | 欧洲精品一区二区 | 国产精品毛片va一区二区三区 | 免费看色片 | av在线免费播放 | 午夜在线免费视频 | 好好的日com| 国产成人午夜 | 美女无遮挡网站 | 日韩精品免费 | 亚洲天堂色图 | 中文字幕理伦片免费看 | 欧美做受| 成人国产精品视频 | 日日舔 | 欧美黄色三级视频 | 精品aaa | 亚洲精品第一页 | 欧美日韩一区在线观看 | 成人毛片网站 | 四虎海外 | 久久九九热 | 亚洲国产欧美日韩在线 | 狠狠干狠狠干 | 91丨九色丨国产在线 | 欧美啪啪网站 | 亚洲国产黄色 | 黄色网址视频 | 亚洲国产成人av | 国产成人av一区二区三区在线观看 | 天天久久 | 日韩精品视频免费在线观看 |