Steven Bethard wrote: > John Salerno wrote: >> If I want to make a list of four items, e.g. L = ['C', 'A', 'D', 'B'], >> and then figure out if a certain element precedes another element, >> what would be the best way to do that? >> >> Looking at the built-in list functions, I thought I could do something >> like: >> >> if L.index('A') < L.index('D'): >> # do some stuff > > This is probably a pretty reasonable approach
Just to clarify, because there seems to be some confusion. I would absolutely go with this approach unless you have profiled and found it to be a bottleneck. It's clear, concise, and quite fast. STeVe -- http://mail.python.org/mailman/listinfo/python-list