The problem is that i have one list like

[l1 l2 l3 l4 l5 l6 l7 l8 ]

no i want to compare l1 with l2 and get some score
then l1 with l3....
and then l1 with l3 , l4 , l5.......... so on
when i am compareing l2 with other elements, in list , i want to avoid comparing it to l1 as l1 compared to l2 is same as l2 compared to l1

please help, though i have written program it works fine but the results has lot of redundancy as given above

infile1 = open(argv[1],'r')
infile2 = open(argv[2],'r')
domain_dict = {}
subclustered_proteins = infile1.readlines()
domain_arrangements = infile2.readlines()
prot = ''
prot2 = ''
for line in domain_arrangements:
        domainlist = line.split()[1:]
        pro_domain = line.split()[0]
        domain_dict[pro_domain] = domainlist
#print domain_dict
for line in subclustered_proteins:
        proteinlist = line.split(':')[1]
        proteins = proteinlist.split()
        for item in proteins:
                prot = item.split('(')[0]
                #print prot,
                a = []
                #if domain_dict.has_key(prot):
                #for key, values in domain_dict:
                        #if key== prot:
                                #print domain_dict(key)
                if prot in domain_dict:
                        #print domain_dict[prot]
                        a = domain_dict[prot]
                        #a = domain_dict[pro_domain]
                        #print key, value
                for item in proteins:
                        prot2 = item.split('(')[0]
                        #print prot2
                        if prot != prot2:
                                if prot2 in domain_dict:
                                        #print domain_dict[prot2]
                                        b = domain_dict[prot2]
                                distance = LD(a,b)
                                print prot + "\t",
                                print '\t'.join(a) + "\t",
                                print prot2 + "\t",
                                print '\t'.join(b) + "\t",
                                print str(distance) + "\t",
6 Years
Discussion Span
Last Post by Gribouillis

You can generate pairs of items to compare with a function

def pairs(alist):
    for i, x in enumerate(alist):
        for y in alist[i+1:]:
            yield x, y

L = list("abcdefgh")
print "initial list: ", L
for u, v in pairs(L):
    print (u, v),

Otheriwse, in your code, the double 'for' loop using the same variable name 'item' is a programming error. The inner loop must always use a different variable name.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.