# creating list n many times

How to define n many empty lists where n is the number of vertices of the given arbitrary graph.

Thanks in advance.

creating list n many times

How to define n many empty lists where n is the number of vertices of the given arbitrary graph.

Thanks in advance.

add a comment

1

If `n`

is your number of vertices, you can for instance create a list of `n`

empty lists as follows:

```
sage: L = [[] for _ in range(n)]
```

And then you can access the (empty) list number `i`

(for `i`

from `0`

to `n-1`

) using:

```
sage: L[i]
[]
sage: L[i].append(0)
sage: L[i]
[0]
```

Asked: **
2015-10-12 08:45:30 -0600
**

Seen: **113 times**

Last updated: **Oct 12 '15**

numerical solutions from a for-loop solve()

Add graphs produced by a for loop?

Swap coordinates of list elements

Not evaluating the coordinates

Print symbolic variables like a_1 in A[1] style

How do I define a list of products of matrices from a given list?

Error when using 'for in range()' but not ' for in [..]'

How to obtain all finite connected distributive lattices with SAGE

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.