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

itertools中chain和chain.from_iterable有什么區別?

What is the difference between chain and chain.from_iterable in itertools?(itertools中chain和chain.from_iterable有什么區別?)
本文介紹了itertools中chain和chain.from_iterable有什么區別?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在互聯網上找不到任何有效的例子,我可以看到它們之間的區別以及為什么要選擇一個而不是另一個.

I could not find any valid example on the internet where I can see the difference between them and why to choose one over the other.

推薦答案

第一個接受 0 個或多個參數,每個參數是一個可迭代對象,第二個接受一個預期生成可迭代對象的參數:

The first takes 0 or more arguments, each an iterable, the second one takes one argument which is expected to produce the iterables:

from itertools import chain

chain(list1, list2, list3)

iterables = [list1, list2, list3]
chain.from_iterable(iterables)

iterables 可以是任何產生可迭代對象的迭代器:

but iterables can be any iterator that yields the iterables:

def gen_iterables():
    for i in range(10):
        yield range(i)

itertools.chain.from_iterable(gen_iterables())

使用第二種形式通常是一種方便的情況,但由于它會延遲循環輸入可迭代對象,因此它也是鏈接無限個有限迭代器的唯一方法:

Using the second form is usually a case of convenience, but because it loops over the input iterables lazily, it is also the only way you can chain an infinite number of finite iterators:

def gen_iterables():
    while True:
        for i in range(5, 10):
            yield range(i)

chain.from_iterable(gen_iterables())

上面的例子將給你一個迭代,它產生一個循環的數字模式,它永遠不會停止,但永遠不會消耗比單個 range() 調用所需更多的內存.

The above example will give you a iterable that yields a cyclic pattern of numbers that will never stop, but will never consume more memory than what a single range() call requires.

這篇關于itertools中chain和chain.from_iterable有什么區別?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 日韩天天操 | 亚洲精品一区二区三区精华液 | av女人的天堂 | 日韩欧美在线一区二区 | 亚洲精品色 | 色八区 | 久久久午夜精品 | 欧美日韩免费在线观看 | 日韩在线专区 | 五月婷婷网 | 欧美精品久 | 日本不卡一区 | 欧美视频在线观看 | 人与拘一级a毛片 | 天堂成人在线 | 草草在线视频 | 国产成人亚洲精品自产在线 | 日韩不卡在线 | 天天天天天操 | 波多野结衣一区二区三区在线观看 | 国产精品久久一区 | 中文字幕一区二区三区视频 | av片免费观看 | 久久久二区 | 婷婷色av | 97在线视频免费观看 | 日韩网站在线观看 | 精品国产乱码久久久久久蜜柚 | 中文字幕精品在线观看 | 99精品久久久久久中文字幕 | 中文字幕在线观看网址 | 色综合久久综合 | 性色av一区二区 | 黄色影院在线观看 | 青青国产| 男女啪啪免费网站 | 国产一级特黄aaa大片 | 懂色av一区二区三区 | 欧美天堂 | 亚洲精品视频免费 | 91精品网站 |