def problem(n): myList = [] for j in range(0, n): number = 2 ** j myList.append(number) return myList
I want this code to return the powers
Yet another simple and efficient solution (every step in O(1)) without the power operator:
def problem(n): return [1 << i for i in range(n)]
The 1 << i operations is a bitwise operation which translates to 2 ^ i for i integer positive.
https://en.wikipedia.org/wiki/Arithmetic_shift