Re: best way to determine sequence ordering?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: best way to determine sequence ordering?

From: Steven Bethard <steven.bethard@gmail.com>
Date: Sun Apr 30 2006 - 02:06:36 CEST

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
Received on Mon May 1 00:45:59 2006