Possible Duplicate:
Creating a list in Python- something sneaky going on?
Creating an empty list in Python
Consider the following:
mylist = list()
and:
mylist = []
Is there any benefit to using list() or [] – should one be used over the other in certain situation?
For an empty list, I’d recommend using
[]. This will be faster, since it avoids the name look-up for the built-in namelist. The built-in name could also be overwritten by a global or local name; this would only affectlist(), not[].The
list()built-in is useful to convert some other iterable to a list, though:For completeness, the timings for the two options for empty lists on my machine (Python 2.7.3rc2, Intel Core 2 Duo):