新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:pythonitertools函數(shù)的多種用法
1、組合可迭代對(duì)象。

成都網(wǎng)絡(luò)公司-成都網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司十余年經(jīng)驗(yàn)成就非凡,專業(yè)從事成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì),成都網(wǎng)頁(yè)設(shè)計(jì),成都網(wǎng)頁(yè)制作,軟文發(fā)布平臺(tái),一元廣告等。十余年來(lái)已成功提供全面的成都網(wǎng)站建設(shè)方案,打造行業(yè)特色的成都網(wǎng)站建設(shè)案例,建站熱線:13518219792,我們期待您的來(lái)電!
import itertools countries = ['USA', 'Australia', 'Canada','Germany'] result = itertools.combinations(countries, 3) for i in result: print(i)
2、允許元素重復(fù)。
import itertools country = ['USA', 'Australia', 'Canada','Germany'] result = itertools.combinations_with_replacement(countries, 3) for i in result: print(i)
3、計(jì)數(shù)。生成一個(gè)迭代器,該迭代器返回以start指定的數(shù)字開頭的均勻間隔值。
在 itertools.count(20,4) 中為 i導(dǎo)入 itertools : print(i) if i > 30: Break
4、像在SQL中一樣將事物組合在一起。
import itertools
countries = [("West", "USA"),
("West", "Canada"),
("East", "Singapore"),
("East", "China")]
iterator_one = itertools.groupby (countries, lambda x : x[0])
for key, group in iterator_one:
result = {key : list(group)}
print(result)以上就是python itertools函數(shù)的多種用法,希望對(duì)大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
當(dāng)前文章:創(chuàng)新互聯(lián)Python教程:pythonitertools函數(shù)的多種用法
鏈接地址:http://fisionsoft.com.cn/article/coccgso.html


咨詢
建站咨詢
