Is it possible to specify the size of list at construction?

Michael Spencer mahs at telcopartners.com
Tue Mar 1 21:38:38 CET 2005


Anthony Liu wrote:
> I cannot figure out how to specify a list of a
> particular size.
> 
> For example, I want to construct a list of size 10,
> how do I do this?
> 
A list does not have a fixed size (as you probably know)

But you can initialize it with 10 somethings
 >
  >>> [None]*10
  [None, None, None, None, None, None, None, None, None, None]
  >>> range(10)
  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  >>>

Michael




More information about the Python-list mailing list