Which is More Efficient?

John Machin sjmachin at lexicon.net
Thu May 18 19:50:19 CEST 2006

1. Think about it. The first case will make a new list and copy "size"
*objects. When the assignment happens, the old list has its reference
count decremented. Not very memory-friendly. The second case merely
truncates the existing list in situ. Bit hard to imagine how the first
case could ever be faster than the second case. You might like to read
the source code. The file that you are looking for is listobject.c.
2. Measure it.
3. Unless you are deliberately parodying b1ff at aol.com, don't use
"L".lower() as a variable name.
4. Try reading this list / newsgroup more often -- (a) this topic (or a
closely related one) was covered within the last week or so (b) you
might notice abuse like (3) above being hurled at others and avoid
copping your share.

More information about the Python-list mailing list