Blog Archive

Wednesday, July 25, 2012

How to Use a Nested Dictionary


Sometimes you will want to look up two sets of criteria... in this case what amino acid is represented by 'A' and what its side chain is

adic={
     'R':{'name':'Arginine','color':'red','shape':'s','sidechain':'poscharged'},
     'H':{'name':'Histidine','color':'Maroon','shape':'s','sidechain':'poscharged'},
     'K':{'name':'Lysine','color':'Salmon','shape':'s','sidechain':'poscharged'},
     'D':{'name':'Aspartic Acid','color':'blue','shape':'s','sidechain':'negcharged'},
     'E':{'name':'Glutamic Acid','color':'DarkBlue','shape':'s','sidechain':'negcharged'},
     'S':{'name':'Serine','color':'Purple','shape':'o','sidechain':'polar'},
     'T':{'name':'Threonine','color':'Indigo','shape':'o','sidechain':'polar'},
     'N':{'name':'Asparagine','color':'DarkViolet','shape':'o','sidechain':'polar'},
     'Q':{'name':'Glutamine','color':'DarkViolet','shape':'o','sidechain':'polar'},
     'C':{'name':'Cystein','color':'Tomato','shape':'^','sidechain':'---'},
     'U':{'name':'Selenocysteine','color':'OrangeRed','shape':'^','sidechain':'---'},
     'G':{'name':'Glycine','color':'DarkOrange','shape':'^','sidechain':'---'},
     'P':{'name':'Proline','color':'Gold','shape':'^','sidechain':'---'},
     'A':{'name':'Alanine','color':'GreenYellow','shape':'D','sidechain':'hydrophobic'},
     'V':{'name':'Valine','color':'SpringGreen','shape':'D','sidechain':'hydrophobic'},
     'I':{'name':'Isoleucine','color':'ForestGreen','shape':'D','sidechain':'hydrophobic'},
     'L':{'name':'Leucine','color':'Lime','shape':'D','sidechain':'hydrophobic'},
     'M':{'name':'Methionine','color':'DarkGreen','shape':'D','sidechain':'hydrophobic'},
     'F':{'name':'Phenylalanine','color':'LimeGreen','shape':'D','sidechain':'hydrophobic'},
     'T':{'name':'Tyrosine','color':'SeaGreen','shape':'D','sidechain':'hydrophobic'},
     'W':{'name':'Tryptophan','color':'MediumSpringGreen','shape':'D','sidechain':'hydrophobic'},
     }

>>> adic['A']['name']
'Alanine'
>>> adic['A']['sidechain']
'hydrophobic'

No comments:

Post a Comment