Concatenating dictionary values and keys, and further operations

Roberto Bonvallet rbonvall at gmail.com
Mon Jun 5 18:35:31 CEST 2006


Girish Sahani <girish at cse.iitb.ac.in>:
> 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
> features.

Note that dictionary keys are not ordered, so--if I understand your
requirement correctly--it could also result in {'ba': [3, 4, 5, 1,
2]}.

> 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.

According to this, I think that you shouldn't concatenate the lists,
but keep them apart instead.

> The information of this connected thing is in a text file as follows:
> 1,'a',2,'b'
> 3,'a',5,'a'
> 3,'a',6,'a'
> 3,'a',7,'b'
> 8,'a',7,'b'
> .
> 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

I don't understand very well what you want to do.  Could you explain
it more clearly, with an example?
-- 
Roberto Bonvallet



More information about the Python-list mailing list