indexed looping, functional replacement?
Brian O. Bush
bushbo at attbi.com
Sat Nov 9 13:37:15 EST 2002
I currently have a list of functions and a list of arguments to the
functions (n to n). Is there a way I can get around having to keep an
index into the arguments as I loop through the functions. Below is my
imperative approach:
def f1(str):
print "f1:", str
def f2(str):
print "f2:", str
def f3(str):
print "f3:", str
str = ["bbb", "sdf", "sdw"]
fn = [f1, f2, f3]
i = 0
for f in fn:
f(str[i])
i = i + 1
I would like a simpler approach to avoid having to manually maintain
an index, maybe functional if possible.
Thanks,
Brian
More information about the Python-list
mailing list