索引三重嵌套列表以在 Python 中分配新值

Indexing triple nested List to assign new values in Python

提问人:Chloe Duckworth 提问时间:10/20/2022 更新时间:10/20/2022 访问量:33

问:

我需要帮助了解如何在 Python 中更新三重嵌套列表中特定数据点的颜色。就目前而言,嵌套的 for 循环每次都使用最近调用的轴的新颜色更新所有轴的数据点,因此 x 轴和 y 轴的颜色是相同的,尽管数据点不同。我需要一些帮助来捕捉这个循环中的问题。

xColors=['#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999','#999999']
yColors=xColors

xData=inputtedData['X Values'] #Series imported from spreadsheet
xData=xData.tolist()
yData=inputtedData['Y Values'] #Series imported from spreadsheet
yData=yData.tolist()

x=[xData,xColors]
y=[yData,yColors]
data=[x,y]

for axis in range(len(data)):
  for indexData in range(0,72):
    if data[axis][0][indexData]==0:
        data[axis][1][indexData]=color0
    elif data[axis][0][indexData]==1:
        data[axis][1][indexData]=color1
    elif data[axis][0][indexData]==2:
        data[axis][1][indexData]=color2
    elif data[axis][0][indexData]==3:
        data[axis][1][indexData]=color3
    elif data[axis][0][indexData]==4:
        data[axis][1][indexData]=color4
    elif data[axis][0][indexData]==5:
        data[axis][1][indexData]=color5 
    elif data[axis][0][indexData]==6:
        data[axis][1][indexData]=color6
    elif data[axis][0][indexData]==7:
        data[axis][1][indexData]=color7
python for-loop 嵌套 循环 嵌套循环 嵌套列表

评论

0赞 Bart 10/20/2022
它不在 for 循环中,并且无法从给定的信息量中重现错误。
0赞 Chloe Duckworth 10/21/2022
刚刚在代码中发现了一个错误,谢谢!

答: 暂无答案