列出从['a','b','c','d','e','f','g','h','i']到[['a','''的列表b”, 'C'],[ 'd', 'E', 'F'],[ 'G', 'H', 'I']]

时间:2013-06-08 03:33:38

标签: python

如何列出以下列表:

data = ['a','b','c','d','e','f','g','h','i']

data = [['a','b','c'],['d','e','f'],['g','h','i']]

1 个答案:

答案 0 :(得分:1)

[a[i:i+3] for i in range(0, len(a), 3)]