Patrick Patrick - 2 years ago 65
Python Question

Initialising an n-length tuple of lists

So in Python, if I wanted to create a list of lists I could do something like:

[[] for _ in range(list_length)]

And to create a tuple of lists of a similar nature I could technically write:

tuple([[] for _ in range(list_length)])

But is this computationally inefficient?

Is there a more efficient, simpler way to create a tuple of lists of length 'n'?

Answer Source

Use a genex instead of a LC.

tuple([] for _ in range(list_length))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download