<div dir="ltr">There is a different algorithm, one that doesn't refer to the previous item in the list, that produces those numbers. Think about what kind of algebraic function generally produces a series of numbers that get farther and farther apart.<br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 4, 2015 at 6:39 PM, Lewit, Douglas <span dir="ltr"><<a href="mailto:d-lewit@neiu.edu" target="_blank">d-lewit@neiu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><font size="4">Hi there,</font><div><font size="4"><br></font></div><div><font size="4">I'm reading this book, "Data Structures & Algorithms in Python" by Goodrich, Tamassia, and Goldwasser. A pretty good book, it really does into detail about the Python language with various examples.</font></div><div><font size="4"><br></font></div><div><font size="4">Anyhow, one of the exercises is as follows:</font></div><div><font size="4"><br></font></div><div><font size="4">Demonstrate how to use Python's list comprehension syntax to produce the list:</font></div><div><font size="4">[0, 2, 6, 12, 20, 30, 42, 56, 72, 90].</font></div><div><font size="4"><br></font></div><div><font size="4">I'm struggling with this!</font></div><div><font size="4"><br></font></div><div><font size="4">The best I can do is the following:</font></div><div><font size="4"><br></font></div><div><font size="4">A = [0]</font></div><div><font size="4">i = 2</font></div><div><font size="4">while i <= 18:</font></div><div><font size="4"> A.append(A[-1] + i)</font></div><div><font size="4"> i+= 2</font></div><div><font size="4"><br></font></div><div><font size="4">print(A)</font></div><div><font size="4"><br></font></div><div><font size="4">Well it does work! BUT it's not a list comprehension!</font></div><div><font size="4"><br></font></div><div><font size="4">Any suggestions?</font></div><div><font size="4"><br></font></div><div><font size="4">Thanks,</font></div><div><font size="4"><br></font></div><div><font size="4">Douglas.</font></div></div>
<br>_______________________________________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org" target="_blank">Chicago@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/chicago" target="_blank">https://mail.python.org/mailman/listinfo/chicago</a><br>
<br></blockquote></div><br></div></div>