preferring [] or () in list of error codes?

Stephen Hansen apt.shansen at gmail.com
Mon Jun 8 17:56:24 EDT 2009


On Mon, Jun 8, 2009 at 2:36 PM, <mh at pixar.com> wrote:

> Is there any reason to prefer one or the other of these statements?
>
>        if e.message.code in [25401,25402,25408]:
>        if e.message.code in (25401,25402,25408):
>
> I'm currently using [], but only coz I think it's prettier
> than ().


I like to use tuples / () if the sequence literal is ultimately static.
Purely because in my mind that just makes it a little more clear-- a list is
mutable, so I use it when it should be or may be mutated; if it never would,
I use a tuple. It just seems clearer to me that way.

But a tuple also takes up a little space in memory, so it's a bit more
efficient that way. I have absolutely no idea if reading / checking for
contents in a list vs tuple has any performance difference, but would
suspect it'd be tiny (and probably irrelevant in a small case like that),
but still.

--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090608/1ded1de1/attachment.html>


More information about the Python-list mailing list