best way to determine sequence ordering?
John Salerno
johnjsal at NOSPAMgmail.com
Fri Apr 28 10:53:55 EDT 2006
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
But I didn't know if maybe there was a preferred method for this type of
operation, or perhaps a better function to use to figure out the
ordering. Or even if I wanted to write my own utility function to make
it look cleaner than above, I'd still need to use something like above
in my function, so I wanted to know what might be the 'cleanest' looking
solution.
Thanks.
More information about the Python-list
mailing list