list index()

Carsten Haese carsten at
Thu Aug 30 20:06:34 CEST 2007

On Thu, 2007-08-30 at 10:44 -0700, zzbbaadd at wrote:
> >
> > How could it not be an exception, in the plain English sense of the
> > word? Most certainly you're asking for the index because you want to do
> > something with the index. If the item is not found, you have no index,
> > so that's a special case that must be handled separately. There is no
> > logical difference between handling that special case in an except
> > clause versus handling it with an if-branch.
> In my case of have done os.listdir() on two directories. I want to see
> what files are in directory A that are not in directory B.
> [...]

list.index() is the wrong tool for that job. Python has sets, use them.

Carsten Haese

More information about the Python-list mailing list