I have a piece of code that looks like this:
myfunction(a, b, c)
myfunction(d, e, f)
myfunction(g, h, i)
myfunction(j, k, l)
The number of arguments do not change, but the function has to be called consecutively with different values each time. These values are not automatically generated and are manually inputted. Is there an inline solution to do this without creating a function to call this function? Something like:
myfunction(a, b, c)(d, e f)(g, h, i)(j, k, l)
Any help appreciated. Thanks in advance!
Simple, use tuple unpacking
tripples = [('a', 'b', 'c'), ('d', 'e', 'f'), ('g', 'h', 'i'), ('j', 'k', 'm')]
for tripple in tripples:
print(myfunction(*tripple))
I'm surprised that nobody mentioned map
map(func, iter)
It maps each iterable in iter
to the func
passed in the first argument.
For your use case it should look like
map(myfunction, *zip((a, b, c), (d, e, f), (g, h, i), (j, k, l)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With