In Python, Can I generate a geometric progression using list comprehensions alone? I don't get how to refer to elements that were added to the list.
That would be like Writing python code to calculate a Geometric progression or Generate list - geometric progression.
If a geometric progression is defined by
a_n = a * r ** (n - 1)
anda_n = r * a_(n - 1)
, then you could just do the following:List comprehensions don't let you refer to previous values. You could get around this by using a more appropriate tool:
or by avoiding the use of previous values: