Transform two tuples item by item
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon Dec 19 22:40:04 EST 2011
On Mon, 19 Dec 2011 18:04:15 -0800, Gnarlodious wrote:
> What is the best way to operate on a tuple of values transforming them
> against a tuple of operations? Result can be a list or tuple:
Create a list of functions:
ops = [lambda obj: obj,
"<span class='H'>{}</span>".format,
bool,
bool,
lambda obj: obj,
bool,
escape,
]
then use zip to pair them up with their arguments:
results = [f(x) for f,x in zip(ops, tup)]
--
Steven
More information about the Python-list
mailing list