Showing posts with label functions. Show all posts
Showing posts with label functions. Show all posts

Thursday, May 21, 2009

How to store functions in a dictionary in Python

This example uses a dictionary to store functions.

To call the function, use the dictionary key.
>>> f = {'plus_all':sum, 'find_max':max}
>>> f['find_max'](1,4,5,3,2,6)
6
>>> f['plus_all'](range(10))
45