Turning a list into nested lists in python

后端 未结 8 1904
天涯浪人
天涯浪人 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:37

    This groups each 3 elements in the order they appear:

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

    Give us a better example if it is not what you want.

提交回复
热议问题