說我有諸如獲取生成一個列表:如何根據變量自定義列表分組?
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