How to multiply all values within a list?

Asked

Viewed 64 times

0

Hi, I’m developing a program that gets a list of bases and exponents. Thus, it performs the potentiation between them and, soon after, multiplies the results. However, I am dubious about the multiplication of results. So far, I have been able to develop this:

def potenciacao(Bases,Expoentes):
    #Recebendo as Bases e Expoentes, ambas armazenadas em listas e possuem o mesmo tamanho
    resultados = [Bases[i]**Expoentes[i] for i in range(len(Bases))]
    # Realizando a potenciação entre eles com um list comprehension
    Resultado = map(lambda x,y = x*y,resultados)
    # Pensei em utilizar a função map do python para realizar isso, mas não consegui 
    return Resultado

Is there a python function that performs this type of operation with lists? Or some method?

  • 1

    Do you need to multiply the results? Wouldn’t you add them up? By the way, the map does not do what you want, it is probably the reduce that you need.

  • Yes, I need to multiply the values contained in the 'results' list'.

  • 1

    Thanks in advance, from the function reduce I was able to accomplish what I needed

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.