def compose(list_of_functions): application_order = reversed(list_of_functions) def composed(x): for f in application_order: x = f(x) return x return composed
reversed returns an iterator to the list in reverse order, not a copy of the list:
>>> lst = range(10) >>> riter = reversed(lst) >>> list(riter) [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] >>> list(riter) []
so you either need to call reversed each time in 'composed' or copy the list and call reverse.
Steve -- http://mail.python.org/mailman/listinfo/python-list