[Tutor] dealing with nested list values in a dictionary

kumar s ps_python at yahoo.com
Fri May 25 04:31:45 CEST 2007


Dear group,

unfortunately my previous post got tagged as
'homework' mail and got no responses. 

In short, I have a dictionary structure as depicted
below. 

I want to go over every key and print the key,value
pairs in a more sensible way. 

I have written a small piece of code. May I request
tutors to go through it and comment if it is correct
or prone to bugs. 

Thank you. 
kum

>>>md = {(21597133, 21597325): [['NM_032457']], 
(21399193, 21399334): [['NM_032456'], ['NM_002589']], 
(21397395, 21399192): [['NM_032457'], ['NM_032456'],
['NM_002589']], 
(21407733, 21408196): [['NM_002589']], 
(21401577, 21402315): [['NM_032456']], 
(21819453, 21820111): [['NM_032457']], 
(21399335, 21401576): [['NM_032457'], ['NM_032456'],
['NM_002589']]}

>>> for item in md.keys():
	mlst = []
	for frnd in md[item]:
		for srnd in frnd:
			mlst.append(srnd)
	mystr = ','.join(mlst)
	print(('%d\t%d\t%s')%(item[0],item[1],mystr))

	
21597133	21597325	NM_032457
21399193	21399334	NM_032456,NM_002589
21397395	21399192	NM_032457,NM_032456,NM_002589
21407733	21408196	NM_002589
21401577	21402315	NM_032456
21819453	21820111	NM_032457
21399335	21401576	NM_032457,NM_032456,NM_002589


      ____________________________________________________________________________________Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 



More information about the Tutor mailing list