#Array
Days = ["Mon 1","Tue 1","Wed 1","Thu 1","Fri 1",
"Mon 2","Tue 2","Wed 2","Thu 2","Fri 2",
"Mon 3","Tue 3","Wed 3" ,"Thu 3","Fri 3",
"Mon 4","Tue 4","Wed 4","Thu 4","Fri 4"]
Route = ["Bus A","Bus B","Bus C","Bus D","Bus E","Bus F"]
#A #B #C #D #E #F
BusData = [[], [], [], [], [], []]
对于此代码,我想请用户在路线中每天输入一个值,并将该信息存储在BusData中。数组应具有以下信息:
BusData = [[Bus A天],[Bus B天],[Bus C天],[Bus D天],[Bus E天],[Bus F天]
我正在考虑使用for循环
答案 0 :(得分:2)
您可以使用词典并将其相应地转换为列表列表。
Days = ["Mon 1","Tue 1","Wed 1","Thu 1","Fri 1",
"Mon 2","Tue 2","Wed 2","Thu 2","Fri 2",
"Mon 3","Tue 3","Wed 3" ,"Thu 3","Fri 3",
"Mon 4","Tue 4","Wed 4","Thu 4","Fri 4"]
Route = ["Bus A","Bus B","Bus C","Bus D","Bus E","Bus F"]
BusData={"Bus A":[],"Bus B":[],"Bus C":[],"Bus D":[],"Bus E":[],"Bus F":[]}
for i in Days:
userInput=input() #type of bus for that particular day
BusData[userInput].append(i)
print(BusData)