【python小随笔】将一个列表的值,分成10个一组,遍历的时候每10个遍历一次

t = [‘B071LF9R6G‘, ‘B0714BP3H4‘, ‘B0756FL8R7‘, ‘B072HX95ZR‘, ‘B07CX389LX‘, ‘B07D9MZ7BD‘, ‘B07D9L15L5‘, ‘B00L1UNPZ0‘,
      ‘B07KDL9RSD‘, ‘B01N02WUM3‘, ‘B072KTNZMW‘, ‘B071Z71BXW‘, ‘B00DU76BOY‘, ‘B07D9NC33M‘, ‘B07G82D89J‘, ‘B076C9X4KS‘,
      ‘B07CTMG6Y9‘, ‘B071JZ78TD‘, ‘B01NBPP89Y‘, ‘B000LJ60F4‘, ‘B07FBJ8CT1‘, ‘B01N77XY1C‘, ‘B06XSCR62Y‘, ‘B078H4FK45‘,
      ‘B01MRVTY7K‘, ‘B07HKH4XMT‘, ‘B0711R3WFH‘, ‘B0725QD6JX‘, ‘B01NCKJSV6‘, ‘2222222222‘, ‘B07HJYHH95‘, ‘B0030MIIOU‘,
      ‘B07HGD4R5N‘, ‘B07PKXNGZH‘, ‘B01HIS1IXE‘, ‘B06XKLFMMV‘, ‘B01DB4TEX0‘, ‘B07B41S34Q‘, ‘B07BL2HT3R‘, ‘B07B712499‘,
      ‘B0716PK6R2‘, ‘B077X9J24C‘, ‘B01N2SBH4J‘, ‘B072854G8H‘, ‘B07KTD2YQ1‘, ‘B07BL3469H‘, ‘B07TJQ5DZN‘, ‘B0711TJZ99‘]

step = 10
b = [t[i:i+step] for i in range(0,len(t),step)]

for x in b:
    print(x)

遍历结果为10个一组 10个一组的遍历

[‘B071LF9R6G‘, ‘B0714BP3H4‘, ‘B0756FL8R7‘, ‘B072HX95ZR‘, ‘B07CX389LX‘, ‘B07D9MZ7BD‘, ‘B07D9L15L5‘, ‘B00L1UNPZ0‘, ‘B07KDL9RSD‘, ‘B01N02WUM3‘]
[‘B072KTNZMW‘, ‘B071Z71BXW‘, ‘B00DU76BOY‘, ‘B07D9NC33M‘, ‘B07G82D89J‘, ‘B076C9X4KS‘, ‘B07CTMG6Y9‘, ‘B071JZ78TD‘, ‘B01NBPP89Y‘, ‘B000LJ60F4‘]
[‘B07FBJ8CT1‘, ‘B01N77XY1C‘, ‘B06XSCR62Y‘, ‘B078H4FK45‘, ‘B01MRVTY7K‘, ‘B07HKH4XMT‘, ‘B0711R3WFH‘, ‘B0725QD6JX‘, ‘B01NCKJSV6‘, ‘2222222222‘]
[‘B07HJYHH95‘, ‘B0030MIIOU‘, ‘B07HGD4R5N‘, ‘B07PKXNGZH‘, ‘B01HIS1IXE‘, ‘B06XKLFMMV‘, ‘B01DB4TEX0‘, ‘B07B41S34Q‘, ‘B07BL2HT3R‘, ‘B07B712499‘]
[‘B0716PK6R2‘, ‘B077X9J24C‘, ‘B01N2SBH4J‘, ‘B072854G8H‘, ‘B07KTD2YQ1‘, ‘B07BL3469H‘, ‘B07TJQ5DZN‘, ‘B0711TJZ99‘]

原文地址:https://www.cnblogs.com/wanghong1994/p/12179127.html

时间: 2024-11-25 18:58:24

【python小随笔】将一个列表的值,分成10个一组,遍历的时候每10个遍历一次的相关文章

python基础之切片列表id值变化

''' 切片复制时的id值与直接赋值的列表不一样 ''' list_pratisce = [5,6,8,9,19] list_pratisce_backup = list_pratisce list_pratisce_backup_qiepian = list_pratisce[:] print('list_pratisce的值是:',id(list_pratisce),'list_pratisce_backup的值是:',id(list_pratisce_backup),'list_prati

python小技巧--通过字典的值(value)求键(key)

思路:通过遍历字典将key ==> vlaue 取出来,将值进行比较,从而获得key. d = {'a':1, 'b':2, 'c':123, 'd':'hello world'} for k,v in d.items():     if v == 'hello world':         print(k)

【python小随笔】进程池 multiprocessing.Pool的简单实现与踩过的坑

#导入进程模块 import multiprocessing #创建进程池 坑:一定要在循环外面创建进程池,不然会一直创建 pool = multiprocessing.Pool(30) for Size in Size_list: index,Size_Asin = Size.xpath('./@value')[0].split(",") Size_Asin_url = "https://www.amazon.cn/dp/%sth=1&psc=1" % S

【python小随笔】python解析xml格式字符串与xml文件

1:解析xml---文件 from xml.dom.minidom import parse import xml.dom.minidom # 使用minidom解析器打开XML文档 DOMTree = xml.dom.minidom.parse("./test.xml") print(DOMTree) collection = DOMTree.documentElement # 集合某个标签 VariationChilds = collection.getElementsByTagN

【python小随笔】python 解析xml数据的新手大坑>>抓取多重标签,遍历各标签的数据

xml文档: <GetMatchingProductResult ASIN="B071LF9R6G" status="Success">...</GetMatchingProductResult> <GetMatchingProductResult ASIN="B0714BP3H4" status="Success">...</GetMatchingProductResult>

【python小随笔】celery周期任务(简单原理)

1:目录结构 |--celery_task |--celery.py # 执行任务的main函数 |--task_one # 第一个任务 |--task_two # 第2个任务 . . . . |--task_. # 第n个任务 2:celery.py from celery import Celery # 导入celery模块 from celery.schedules import crontab # 周期定义工具包 # 配置任务 celery_task = Celery( "task&qu

Python学习笔记(1)-列表

列表是什么? 列表由一系列按特定顺序排列的元素组成.列表看起来像这样:[1,2,3,4,1].在列表中,可以由零个或多个元素组成,元素之间用逗号分开,具有相同值元素允许出现多次 使用[ ]或list()创建列表 例如创建一个空列表 empty_list = [ ]或者 empty_list = list() 使用list()将其他数据类型转换成列表 字符串列表: >>> list('cat') ['c', 'a', 't'] 元组列表: >>> num = (1,2,3

python 字典合并,字典取值,列表转字典

1.字典的合并 # 第一种 用Python的内置方法,dict与**解包的方式 >>> a = {'name':1,'b':2} >>> b = {'name':1, 'c':10} >>> c = dict(a, **b) >>> c {'name': 1, 'b': 2, 'c': 10} # 第二种 用字典的update()方法 # 可以带权重的,是用b中的元素将a中的元素更新,a的元素会发生改变,但是内存地址不会发生改变 &g

通过遍历而非排序求最值 python list in 时间复杂度 列表元素存在性

Write a function: def solution(A) that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A. For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5. Given A = [1, 2, 3], the