newbie question

Dan Stromberg drsalists at gmail.com
Fri Apr 1 23:06:30 CEST 2011


On Fri, Apr 1, 2011 at 12:52 PM, Karl <8213543GGXNVJXACA at kabelmail.de>wrote:

>  Hello,
>
>
> one beginner question:
>
>
> aList = [0, 1, 2, 3, 4]
>
> bList = [2*i for i in aList]
>
> sum = 0
>
> for j in bList:
>
This iterates over the values in bList, not its indices.

>  sum = sum + bList[j]
>
So instead of adding bList[0] .. bList[4], consecutively, you're adding
bList[0] .. bList[8] skipping every other element - but there aren't that
many elements.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110401/b13d53ea/attachment.html>


More information about the Python-list mailing list