Turning a list into nested lists in python

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

    I hope this will be helpful to you. It converts a list into a list of lists

    list1= [ i for i in range(0,8+1] nested =[] for i in list1: if len(nested) !=0: if i %3!=0: nested.append([i]) else: nested[len(nested)-1].append(i) else: nested.append([i]) print(nested

提交回复
热议问题