Jump to content

Recommended Posts

Posted

Boa tarde estou aqui com algumas duvidas

Quero criar um função "redI" que recebe os mesmos parâmetros que o reduce(função,lista,elemento) mas esta função é para retornar uma lista com todos os passos do acumulador.

Exemplo:

>>> redI(lambda acc, x: acc + x, [3, 5, 2, 1], 0)
[0, 3, 8, 10, 11]

def redI(f,l,e):
    if len(l)==0:
        return e
    else:
        return map(f,l)

print redI(lambda acc, x: acc + x, [3, 5, 2, 1], 0)

ao correr isto ele deveria retornar a lista com a função aplicada mas esta me a dar um erro por estar a dar dois argumentos ao lambda precisava de uma ajuda aqui.

Desde já Obrigado

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.