我想将输入附加到二维数组中的特定位置。任务是输入我自己的数据来替换数组中的一个位置。
#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"]
#The array in each bus is (Mon 1 - Fri 4 in each bus)
BusData = [[0,0,0,2,2,4,0,3,4,-2,-5,0,0,3,4,-1,8,1,1,-2], #Bus A
[0,1,0,0,1,2,0,0,0,0,1,0,0,0,2,0,0,1,0,0], #Bus B
[2,0,-1,-1,-2,-2,-3,-1,0,0,-2,0,1,1,1,1,-1,-1,2,-1], #Bus C
[1,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0], #Bus D
[-1,-1,-1,-2,-4,-10,-2,0,0,0,0,1,2,-3,1,1,3,-1,0,0], #Bus E
[0,-5,-5,-5,-4,-3,-5,0,0,0,0,-2,-3,1,1,1,0,0,-2,-5]] #Bus F
比如我输入了日期和路线,并尝试使用索引位置将其放入数组中。
我试图做这样的解决方案:
#Input values in array
for i in Route: #Finding index of input in array
if Bus == i:
RoutePos = Route.index(i)
for i in Days: #Finding index of input in array
if Day == i:
DayPos = Days.index(i)
DataPos = BusData[RoutePos][DayPos]
BusData.append(DataPos)
print(BusData)
如果有人想让我详细说明这个问题,请告诉我
忽然笑
炎炎设计
繁华开满天机
相关分类