明霞山资源网 Design By www.htccd.com
我就废话不多说了,直接上代码吧!
#方法一 def list_cut(mylist,count): length=len(mylist) merchant=length//count re_merchant=merchant+1*(0 if length%count==0 else 1) begin=0 result_list = [] while (count>0): result_list.append(mylist[begin:begin+re_merchant]) begin=begin+re_merchant count=count-1 return result_list mylist=[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8] hello=list_cut(mylist,5)
#方法二 def list_cut2(mylist,count): length = len(mylist) merchant = length // count re_merchant = merchant + 1 * (0 if length % count == 0 else 1) print(re_merchant) return [mylist[i:i+re_merchant] for i in range(0,length,re_merchant)] hello2=list_cut2(mylist,6)
以上这篇python 实现list或string按指定分段就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
明霞山资源网 Design By www.htccd.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
明霞山资源网 Design By www.htccd.com
暂无评论...