pythonlistloopsexponent

How would I raise integers in a list to successive powers? (python)


Beginner here.

I want to raise elements(integers) in the list to the power of x+1, but am stuck.

For example:

Another example:

[8^2, 7^3, 8^4, 5^5, 7^6] is the output I would like..

Thank you!!!

I tried various for-loops to iterate into the elements of the list; pow(iterable, x+1). I've been at it for a few days but can't figure it out. I am also new to programming in general.


Solution

  • Try:

    lst = [8, 7, 8, 5, 7]
    x = 2
    
    out = [v ** i for i, v in enumerate(lst, x)]
    print(out)
    

    Prints:

    [64, 343, 4096, 3125, 117649]