Concatenating dictionary values and keys, and further operations

Girish Sahani girish at
Mon Jun 5 05:49:39 CEST 2006

I wrote the following code to concatenate every 2 keys of a dictionary and
their corresponding values.
e.g if i have tiDict1 = tiDict1 = {'a':[1,2],'b':[3,4,5]} i should get
tiDict2={'ab':[1,2][3,4,5]} and similarly for dicts with larger no. of
Now i want to check each pair to see if they are connected...element of
this pair will be one from the first list and one from the second....e.g
for 'ab' i want to check if 1 and 3 are connected,then 1 and 4,then 1 and
5,then 2 and 3,then 2 and 4,then 2 and 5.
The information of this connected thing is in a text file as follows:
This means 1(type 'a') and 2(type 'b') are connected,3 and 5 are connected
and so on.
I am not able to figure out how to do this.Any pointers would be helpful
Here is the code i have written till now:
def genTI(tiDict):
    tiDict1 = {}
    tiList = [tiDict1.keys(),tiDict1.values()]
    length =len(tiDict1.keys())-1
    for i in range(0,length,1):
        for j in range(0,length,1):
            for k in range(1,length+1,1):
                if j+k <= length:
                    key = tiList[i][j] + tiList[i][j+k]
                    value = [tiList[i+1][j],tiList[i+1][j+k]]
                    tiDict2[key] = value
        return tiDict2
Thanks in advance,

More information about the Python-list mailing list