Python functions as dictionary values
Dec 21, 2015 • 2 minutes to read • Last Updated: Oct 29, 2017Pro pythonistas will tell you that you should actually be using python with higher order functions & as first class functions. Passing around functions are any programming languages greatest attribute. Here’s a trick to making function calls using python dictionaries.
Consider you have some functions add
, subtract
, divide
and multiply
. You could call these functions from a python dictionary like so:
To use variable size of arguments you could call the operations
dictionary with *args
I would love to hear what you think about this post, also know about your tricks to using python in the comments below.
I am writing a book!
While I do appreciate you reading my blog posts, I would like to draw your attention to another project of mine. I have slowly begun to write a book on how to build web scrapers with python. I go over topics on how to start with scrapy and end with building large scale automated scraping systems.
If you are looking to build web scrapers at scale or just receiving more anecdotes on python then please signup to the email list below.