[Tutor] Array

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Wed Jan 29 13:09:28 2003


On Wed, 29 Jan 2003, Denis Hanley wrote:

> Dear All,
>
> what I need to do is create an Array.  Input Information into the Array
> on the fly and then output my data in this format:
>
> LineData = array[x1 y1, x2 y2, x3 y3, etc]
>
> Line x1 y1  x2 y2
> Line x2 y2 x3 y3
> Line x3 y3 x4 y4

Hi Denis,


Python supports a more flexible data structure called the "List" that we
can use to collect a bunch of data:

    http://www.python.org/doc/tut/node5.html#SECTION005140000000000000000
    http://www.python.org/doc/tut/node7.html#SECTION007100000000000000000

Lists support on-the-fly appending, so they should be suitable for the
task you're describing.  Once you have your points stored in a List, it
shouldn't be too bad to iterate between adjacent pairs and print out the
Line descriptions you want.

Try going through some of the List examples in the links above.  If you
run into problems, please feel free to send a holler on Tutor; we'll be
happy to help!