Turning a list into nested lists in python

后端 未结 8 1925
天涯浪人
天涯浪人 2020-11-30 05:15

Possible Duplicate:
How can I turn a list into an array in python?

How can I turn a list such as:

<         


        
8条回答
  •  广开言路
    2020-11-30 05:49

    new_list = [data_list[x:x+3] for x in range(0, len(data_list) - 2, 3)]

    List comprehensions for the win :)

提交回复
热议问题