2014-02-15 176 views
1

我有兩個multiD列出循環通過兩個多維數組

list one [["hello","how", "are", "you"]] and 
list two [["ss", "gg", "ff"]] 

我想與所有的行值的列表中有兩個比較每一行的列表中的一個。

If list one has 2 rows with arrays list[2][values] 
and list two has 3 rows with arrays list[3][values] 
then 

list one [0][all values] compare with 
    list two[0][values], 
    list two[1][values], 
    list two[2][values], and 
    list two[3][values]. 
Then take row two of list one and compare it with 
    all rows in list two again 
    and so on. 

怎麼可能做到?

+1

我不明白你的解釋。你可以發佈樣本輸入和輸出嗎? –

+1

您是否嘗試編寫任何代碼到目前爲止? SO不是要求別人代表你做的東西,而是一個你可以得到* help * – zmo

+0

的地方。我做不到。這就是爲什麼我問 – user3149650

回答

0

由於你的問題是僞代碼,我會以同樣的方式迴應。 ;-)

for all rows in list1: 
    for all rows in list2: 
     %comparison of rows.. 
     matches = set(current row of list1) & set(current row of list2) 

基本上,this SO question/answer應該涵蓋你的問題。 可能的是,解決方案有更高效的方法。我自己是一名Python初學者。

0

因此,考慮

A = [[1,2,3],[4,5,6],[7,8,9]] 
B = [[11,12,13],[14,15,16],[17,18,19]] 

這是你想要的嗎?

for a_row in A: 
    for b_row_i in xrange(len(B)): 
    print 'compare', a_row, B[b_row_i] 
3

基本上,它是嵌套for循環。你可以使用列表理解來做到這一點。

matches = [(A.index(a),B.index(b)) for a in A for b in B if len(set(a).intersection(set(b)))]