Compare Tuples and find next index in it's same position in python

落爺英雄遲暮 提交于 2019-12-24 08:39:17

问题


R=[(1,10,14,34),(2,5,19,21),(3,7,31,32),(1,9,12,31),(2,10,11‌​,22),(4,8,14,32),(13‌​,15,19,34),(1,5,15,2‌​0),(3,26,19,25),(4,1‌​7,19,21),(4,1‌​7,20,21)]

For each tuple in R, find the next index of each elements with the same element position where other elements should not be present in both tuples.

FOR Index 0 and 1 here is expected sample results

0: 4,5,6,7  
1: 2,5,6,8
.
.
.
.
.
so on

Here is my code is going too detail and too lengthy and taking too long to run for my actual project. so i gave a sample above pls help me to drive this in a optimistic way.., to achieve the speed.

for j in range(i+1,i+10):
        b=set(Results[j])
        if (len(a&b)==0):

            for k in range(i+10, i+200):
                c=set(Results[k])
                if ( (len(a&c)==0) and (len(b&c)==0) ):

                    for l in range(i+200, i+600):
                        d=set(Results[l])
                        if ( (len(a&d)==0) and (len(b&d)==0)  and (len(c&d)==0) ):

                            for m in range(i+500, i+1000):
                                e=set(Results[m])
                                if ( (len(a&e)==0) and (len(b&e)==0)  and (len(c&e)==0)   and (len(d&e)==0) ):

                                    for n in range(i+1000, i+2000):
                                        f=set(Results[n])
                                        if ( (len(a&f)==0) and (len(b&f)==0)  and (len(c&f)==0)   and (len(d&f)==0)   and (len(e&f)==0) ):

                                            for o in range(i+2000, i+3000):
                                                g=set(Results[o])
                                                if ( (len(a&g)==0) and (len(b&g)==0)  and (len(c&g)==0)   and (len(d&g)==0)   and (len(e&g)==0)  and (len(f&g)==0) ):              

                                                        for p in range(i+3000, XRUN):
                                                            h=set(Results[p])
                                                            if ( (len(a&h)==0) and (len(b&h)==0)  and (len(c&h)==0)   and (len(d&h)==0)   and (len(e&h)==0)  and (len(f&h)==0)  and (len(g&h)==0)):              

                                                                CN=CN+1

Thanks in advance.

来源:https://stackoverflow.com/questions/44558290/compare-tuples-and-find-next-index-in-its-same-position-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!