Is there idiomatic and/or elegant Python for zipping and applying a list of functions over a list of values?
For example, suppose you have a list of functions:
functions = [int, unicode, float, lambda x: '~' + x + '~']
and a list of values:
values = ['33', '\xc3\xa4', '3.14', 'flange']
Is there a way to apply the ith function to the ith value and return a list of the same length of the transformed values, while avoiding this ugly list comprehension?
[functions[i](values[i]) for i in range(len(functions))] # <- ugly
What I want is something like zip() + map() (zipmap()!) the functions list with the values list and have the functions be applied to their paired values. I thought itertools might offer something relevant, but functions like imap and starmap are for mapping a single function over an iterable, not an iterable of functions over another iterable.
These solutions seem overly complicated:
mapalready zips its arguments:Or, if you prefer the iterator version: