print lift_middle_child(('A',('B',),('C',),('D',)))# could use lists too
def compose2(a,b): # might want to get this from the functional library
returnlambda *x: a(b(*x))
def compose(*funcs): #compose(a,b,c) = a(b(c(x))) - you might want to reverse that
returnreduce(compose2,funcs)
def reverse_children(in_tree):
return in_tree[0:1] + in_tree[1:][::-1]# slightly cryptic, but works for anything subscriptable
lift_and_reverse = compose(reverse_children,lift_middle_child)# right most function applied first - if you find this confusing, reverse order in compose function.