How to create a list or tuple of empty lists in Python?

后端 未结 5 1674
不知归路
不知归路 2020-12-04 21:42

I need to incrementally fill a list or a tuple of lists. Something that looks like this:

result = []
firstTime = True
for i in range(x):
    for j in someLis         


        
5条回答
  •  醉梦人生
    2020-12-04 22:28

    Please include runnable sample code, so we can run the code ourself to quickly see exactly what it is you want to do. It looks like you just want this:

    result = []
    for i in range(x):
        data = []
        for j in someListOfElements:
            data.append(j)
        # or data = [j for j in someListOfElements]
        result.append(data)
    

提交回复
热议问题