码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2020-01-11 11:42:15      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:10个   一个   span   pytho   小随笔   列表   遍历   python   fmm   

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‘]

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

标签:10个   一个   span   pytho   小随笔   列表   遍历   python   fmm   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!