以下是我目前所掌握的情况:
TotalLists=int(input("How many Lists are you making?"))
TotalListsBackup=TotalLists
Lists=[]
while TotalLists>0:
ListName=input("What would you like to call List Number "+str(TotalLists))
Lists.append(ListName)
TotalLists=TotalLists-1
TotalLists=TotalListsBackup-1
while TotalLists>=0:
Lists[TotalLists] #I would like to create actual lists out of the list names at this step but I dont know how...
TotalLists=TotalLists-1
TotalLists=TotalListsBackup-1
print("Here are your Lists: ")
while TotalLists>=0:
print(Lists[TotalLists])
TotalLists=TotalLists-1
我希望能够:
例如,我想输入:杂货店, 代码将创建一个名为“杂货店”的列表
我想到的解决方案:
阵列?(我从未使用过它们,我对Python编程非常陌生,也不知道太多)
列表列表?(不知道该怎么做。查了一下,没有得到一个明确的答案)
使用变量,创建具有以下名称的列表:
List1[]
有各种各样的叫法:
List1Name=input("What would you like to call list 1?")
不过,我不知道如何使用这种方法创建无限多个列表。在
如果你有什么问题请问,因为我知道我不善于解释。在
你在解决XY问题。不需要事先询问
list
的数量。我建议使用字典:有趣的是,你给问题加上了“字典”的标签,但在帖子中却没有提及。有人叫你用字典吗?您应该这样做(假设totalists已经定义):
最后是一个dictionary d,其中包含用户输入名称的键和空列表中的值。字典词条的数目是总数。我忽略了用户输入相同名称两次的可能性。在
相关问题 更多 >
编程相关推荐