initializing list with number of elements given by a variable

Andy Gimblett gimbo at ftech.net
Thu Apr 11 05:33:29 EDT 2002


On Thu, Apr 11, 2002 at 11:22:46AM +0200, Oliver Pust wrote:

> So something like this:
> 
> >>> length_of_list = 6
> >>> list = ????????? # what to place here, is the question
> >>> print list
> >>> [0,0,0,0,0,0]    # the resulting list should look like this

Here ya go:

>>> l = [0] * 6   
>>> l
[0, 0, 0, 0, 0, 0]

Cheers,

Andy

-- 
Andy Gimblett - Programmer - Frontier Internet Services Limited
Tel: 029 20 820 044 Fax: 029 20 820 035 http://www.frontier.net.uk/
Statements made are at all times subject to Frontier's Terms and
Conditions of Business, which are available upon request.





More information about the Python-list mailing list