1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Composing functions in python

Discussão em 'Python' iniciado por Stack, Setembro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I have an array of functions and I'm trying to produce one function which consists of the composition of the elements in my array. My approach is:

    def compose(list):
    if len(list) == 1:
    return lambda x:list[0](x)
    list.reverse()
    final=lambda x:x
    for f in list:
    final=lambda x:f(final(x))
    return final


    This method doesn't seems to be working, help will be appreciated.

    (I'm reversing the list because this is the order of composition I want the functions to be)

    Continue reading...

Compartilhe esta Página