我正在尝试将卡片放入8个空列表的列表中。我需要列表1-4每个有7张卡,而列表5-8每张有6张卡。我已经导入了一个卡片模块,我只是不确定如何以特定的方式将卡片放入每个列表中。
import cards
list_of_lists = [[],[],[],[],[],[],[],[]]
for L in list_of_lists:
print(L)
目前,我只能打印出来:
[]
[]
[]
[]
[]
[]
[]
[]
如何用卡片填写每张清单?提前致谢
答案 0 :(得分:0)
您可以执行以下操作(get_card()方法用于模拟您的卡片导入):
def get_card():
return "spade"
lol = [
[None] * 7, [None] * 7, [None] * 7, [None] * 7,
[None] * 6, [None] * 6, [None] * 6, [None] * 6,
]
for l in lol:
for index, card in enumerate(l):
l[index] = get_card()
for l in lol:
print(l)
运行时,值如下所示: Result