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

Posted wanghong1994

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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‘]

以上是关于python小随笔将一个列表的值,分成10个一组,遍历的时候每10个遍历一次的主要内容,如果未能解决你的问题,请参考以下文章

js小方法积累,将一个数组按照n个一份,分成若干数组

leetcode25. K 个一组翻转链表---python

leetcode25. K 个一组翻转链表---python

leetcode25. K 个一组翻转链表---python

在javascript中将数组分成3组[重复]

一级和二级的列表在一起的时候。获取一级放在轮播里面展示。10个一组轮播