Quote:
|
Originally Posted by Cerulean
def add(a, b):
return a + b Funny, I find the opposite. Care to post your benchmark?
|
Cerulean's way is preferable, but if you really really want wrapped dispatch:
import operator
def do_operation(op, a, b):
return {'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.div}[op](a, b)
print do_operation('+', 2, 5) The relative difference between the speed of map() and listcomps varies depending on version - Dietrich might be running on 2.2 or 2.3 rather than 2.4?
--OH.