def compogen(g_s, symbol):
 if (len(g_s) == 1):
  return g_s[0]
 foo = g_s[0].subs(symbol, g_s[1])
 if (len(g_s) == 2):
  return foo
 return compogen(([foo] + g_s[2:]), symbol)

def compogen ( g_s , symbol ) : if ( len ( g_s ) == 1 ) : return g_s [ 0 ] foo = g_s [ 0 ] . subs ( symbol , g_s [ 1 ] ) if ( len ( g_s ) == 2 ) : return foo return compogen ( ( [ foo ] + g_s [ 2 : ] ) , symbol )
returns the composition of functions .