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

Carl Banks pavlovevidence at
Tue Jun 9 02:37:28 CEST 2009

On Jun 8, 4:43 pm, Ben Finney <ben+pyt... at> wrote:
> m... at writes:
> > 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 ().
> Use a list when the semantic meaning of an item doesn't depend on all
> the other items: it's “only” a collection of values.
> Your list of message codes is a good example: if a value appears at
> index 3, that doesn't make it mean something different from the same
> value appearing at index 2.
> Use a tuple when the semantic meaning of the items are bound together,
> and it makes more sense to speak of all the items as a single structured
> value.

If you want to go strictly by the book, I would say he ought to be
using a set since his collection of numbers has no meaningful order
nor does it make sense to list any item twice.

I don't think it's very important, however, to stick to rules like
that for objects that don't live for more than a single line of code.

Carl Banks

More information about the Python-list mailing list