On Dec 2, 3:01 am, alex23 <[EMAIL PROTECTED]> wrote: > On Dec 2, 5:31 am, Aaron Scott <[EMAIL PROTECTED]> wrote: > > > I was using .index on the > > list, but it would return True for strings that contained the search > > string rather than match it exactly, leading to false positives in my > > code. > > Are you sure? That doesn't seem like standard behaviour. > > >>> l = ["one", "two", "three", "four"] > >>> l.index('on') > > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > ValueError: list.index(x): x not in list>>> l.index('thre') > > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > ValueError: list.index(x): x not in list > > The only time I'd expect it to do partial matches is if you were doing > string.index(string), rather than list.index(string): > > >>> "four".index('our') > > 1
It would if the OP was iterating over the list and checking that item with .index so it uses the string.index instead of list.index -- http://mail.python.org/mailman/listinfo/python-list