print 'by index'timeit timeit(stmt "mydict[' ']"setup="mydict {' ': ' ': ' ': }"number )print 'by get'timeit timeit(stmt 'mydict get(" ")'setup 'mydict {" ": " ": " ": }'number )output by indexby get above we use two different method by subscript and get to access the dictionary key value we execute statement million times as it executes too fast for very small data now we can see the index access much faster as compared to the get we can run the code multiply times and there will be slight variation in the time execution to get the better understanding another way is to run the above test in the command line let' do itc:\python\python >python - timeit - - "mydict {' ' ' ': ' ': }"mydict[' '] loopsbest of usec per loop :\python\python >python - timeit - - "mydict {' ' ' ': ' ': }"mydict get(' ') loopsbest of usec per loop above output may vary based on your system hardware and what all applications are running currently in your system below we can use the timeit moduleif we want to call to function as we can add multiple statement inside the function to test import timeit def testme(this_dictkey)return this_dict[keyprint (timeit timeit("testme(mydictkey)"setup ="from __main__ import testmemydict {' ': ' ': ' ': }key=' '"number= )output