[Tutor] IndexError and appending to lists [Was: Re: Need Help on Assignment]

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Aug 24 02:14:30 CEST 2005

> >Anyway, this doesn't answer the problem: how do we add elements to a
> >list? In Python, we can accumulate elements in a list by append()ing:

[code cut]

> So, for example, would I use the following in my "while" loop:
>                       date.append(T[N][0])
> Before the loop, date would have to be defined as date =[], is this
> correct?

Yes.  Each of the list variables that you're accumulating should each be
initialized to an empty list.

Good luck!

More information about the Tutor mailing list