How to create and fill a list of lists in a for loop

后端 未结 6 2085
轮回少年
轮回少年 2020-12-15 01:22

I\'m trying to populate a list with a for loop. This is what I have so far:

newlist = []
for x in range(10):
    for y in range(10):
        newlist.append(y         


        
6条回答
  •  -上瘾入骨i
    2020-12-15 01:53

    You should put a intermiate list to get another level

    newlist = []
    for x in range(10):
        temp_list = []
        for y in range(10):
            temp_list.append(y)
        newlist.append(temp_list)
    

提交回复
热议问题