Dictionary exists fetch and non-exist fetch : Dictionary Tuple « Dictionary « Python






Dictionary exists fetch and non-exist fetch

Dictionary exists fetch and non-exist fetch
Matrix = {}

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

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

print Matrix

print Matrix.get((2,3,4), 0)          # exists-fetch and return

Matrix.get((2,3,6), 0)          # does not exist-use default arg


           
       








Related examples in the same category

1.Use tuple as keyUse tuple as key
2.Define tuple as key in a dictionaryDefine tuple as key in a dictionary