Define tuple as key in a dictionary : Dictionary Tuple « Dictionary « Python






Define tuple as key in a dictionary

Define tuple as key in a dictionary

Matrix = {}

Matrix[(2,3,4)] = 88

Matrix[(7,8,9)] = 99

X = 2; Y = 3; Z = 4              # ; separates statements

print Matrix[(X,Y,Z)]

print Matrix

if Matrix.has_key((2,3,6)):     # check for key before fetch
     print Matrix[(2,3,6)]
else:
     print 0

           
       








Related examples in the same category

1.Use tuple as keyUse tuple as key
2.Dictionary exists fetch and non-exist fetchDictionary exists fetch and non-exist fetch