arrays in python

Benjamin Kaplan bsk16 at
Wed Sep 23 19:24:38 CEST 2009

On Sep 23, 2009, at 1:16 PM, Rudolf <yellowblueyellow at> wrote:

> Can someone tell me how to allocate single and multidimensional arrays
> in python. I looked online and it says to do the following x =
> ['1','2','3','4']
> However, I want a much larger array like a 100 elements, so I cant
> possibly do that. I want to allocate an array and then populate it
> using a for loop. Thanks for your help.

Python lists have a dynamic size so you don't usually do that.
Instead, we use list comprehensions to stick the for loop inside the
list declaration.

[str(x) for x in xrange(100)]

> --

More information about the Python-list mailing list