list index question

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Tue Apr 1 23:53:38 CEST 2003


> From: Matt Singer [mailto:mrsinger at usa.net]
> 
> Can I wildcard? I don't know the values in the second column.  I want
> to find the first entry what has a particular value in the first
> column.

That's not at all what you said. Next time, please ask the question you want an answer to. Anna's response was perfectly correct for the question you asked.

http://www.catb.org/~esr/faqs/smart-questions.html

No, you cannot wildcard - it doesn't make sense for this.

You need to define you problem further.

1. Do you want the *index* of the first tuple which matches or
2. Do you want the first tuple that matches itself.
3. Is the data in the sequence sorted? If so, how?

In any case, since you already have the data in a sequence, looping is probably the best option here - it has the advantage of being O(N). If the data is already sorted in a way that you want, you may be able to use a more efficient search algorithm to find *one* of the entries that matches, then search backwards until you find one that doesn't match.

Tim Delaney





More information about the Python-list mailing list