说我有诸如获取生成一个列表:如何根据变量自定义列表分组?
list_x = [0,1,2,3,4,5,6,7,8,9]
然后我把它像这样:
list_x = [01,23,45,67,89]
与此列表理解:
list_x = [0,1,2,3,4,5,6,7,8,9]
grp_count = 2
new_list = map(int, [list_x[i+0]+list_x[i+1] for i in range(0, len(list_x)-1, grp_count)])
哪有我使这个代码,所以我可以将它分组为基于`grp_count'
例如,如果group_count = 5
:
list_x = [,56789]
我知道我必须插入多个list_x[i+n]
每次添加的分组大小的莫名其妙。
你的代码提供'1,5,9,13,17'。那是你需要的吗? – Psidom
默认情况下,Python不显示整数的前导零。 – martineau
什么应该是列表中的returnformat:strings(python中的字符列表)? O元组? – inetphantom