在Python中嵌套

A77*_*7ak 1 python nested python-2.7

我有一个列表,我想迭代它,然后迭代嵌入for在第一个我读过的下一个位置的同一个列表中的第一个.

在像Java这样的语言中:

int[10] array;
for (int i=0; i < array.length(); i++)
    for (int j=i+1; j < array.length(); j ++)
        //do something with the array comparing a[i] and a[j]
Run Code Online (Sandbox Code Playgroud)

我怎么能在Python上做到这一点?我试试这个:

for a in array:
     del array[0]
     for a2 in array:
         //do something with the array comparing a and a2
Run Code Online (Sandbox Code Playgroud)

但只适用于第一次迭代..任何帮助?

Kei*_*wan 6

for i in range(0,len(array)):
    for j in range(i+1,len(array)):
        #do something with array[i] and array[j]
Run Code Online (Sandbox Code Playgroud)