首页 > 其他 > 详细

list分组

时间:2019-10-09 21:02:35      阅读:79      评论:0      收藏:0      [点我收藏+]
def list_of_groups(init_list, children_list_len):
    list_of_groups = zip(*(iter(init_list),)   *children_list_len)
    end_list = [list(i) for i in list_of_groups]
    count = len(init_list) % children_list_len
    end_list.append(init_list[-count:]) if count !=0 else end_list
    return end_list

texts = [(3,4),(5,6),(8,9),(0,2),(5,30),(45,50),(5,6),(8,9),(0,2),(5,30)]
split_txt = list_of_groups(texts, 3)
print(split_txt)

 

list分组

原文:https://www.cnblogs.com/zongfa/p/11644089.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!