[Tutor] handling tuples in a dictionary

Jimmy verma jim_938 at hotmail.com
Sun Sep 28 10:31:32 EDT 2003


Hello,

Thanks to everyone on tutor list for providing their valuable support.

I am having my problem like this:

I have a dictionary with items of the following form:

dict = {('x',1): -100, ('y',2):-200, ('x',2):100, ('z',3):150, ('y', 4):50}

I have tuple as the keys.


What i want is to have this information in this form in order to make the 
combinations:

Letter  'X'
set     1   R  -100
set    2   R  100


Letter 'Y'
set  2  R  -200
set  4  R  50


Letter 'Z'
set  3  R  150



I mean i want for all the tuples that whose first letter is same they should 
be put in one group and their values listed like i have written above.


I have tried to take the dict.keys() and then sort these values but not 
getting to know completely how can i achieve this.

You suggestions will be highly appriciated.

Thanks in advance.

Regards,

J+

_________________________________________________________________
Calling all NRIs! Avail of the best financial services. 
http://server1.msn.co.in/msnspecials/nriservices/index.asp Smile all the way 
with ICICI Bank.




More information about the Tutor mailing list