Which is More Efficient?

Dustan DustanGroups at gmail.com
Fri May 19 00:19:13 CEST 2006


John Machin wrote:
> 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.

That's what I thought. I wasn't sure exactly what del actually does.

> 2. Measure it.

Tell me how and I will; I'm not nearly that much of a geek
unfortunately.

> 3. Unless you are deliberately parodying b1ff at aol.com, don't use
> "L".lower() as a variable name.

Don't understand what you mean by this, but I didn't actually use 'l'
as a variable name; that was just an example.

> 4. Try reading this list / newsgroup more often

I follow too many newsgroups as it is, when I've got plenty of other
stuff to do.

> -- (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.



> HTH,
> John




More information about the Python-list mailing list