如何在Python中定义多维数组

时间:2017-11-22 10:26:43

标签: python multidimensional-array

我正在使用Tkinter进行Python的GUI编程。 我想定义一个多维数组。我尝试了以下代码,但它显示错误。

subMenu =[sub1[],sub2[],sub3[],sub4[],sub5[]]

sub1 = ["New File","Save File","Edit File","Open File","Exit"]
sub2 = ["Undo","Redo","Cut","Copy","Paste"]
sub3 = ["Run","Check Module","Debug","compile","Close"]
sub4 = ["Undo","Redo","Cut","Copy","Paste"]
sub5 = ["Undo","Redo","Cut","Copy","Paste"]

如何在Python中定义多维数组?

1 个答案:

答案 0 :(得分:0)

在列表中分配列表时出错。 它应该是

var i,
    count = {},
    index;

for (i = 0; i < 1e6; i++) {
    index = Math.floor(Math.random() * 18 + 2) % 10;
    count[index] = (count[index] || 0) + 1;
}

console.log(count);

当您尝试打印subMenu时,它应该是这样的: enter image description here