How to find an item/items in a list?

Bjorn Pettersen BPettersen at NAREX.com
Mon May 5 12:35:19 EDT 2003


So, for some reasong I've been trying to find the "next" value (or all
following values) after a certain "item" in a list. It's easy to do:

  nextVals = lst[lst.index(item)+1:]

but this can throw (which is a pain, especially when the algorithm
naturally deal with an empty nextVals :-).

Is there a better way of doing this? I was thinking perhaps a "value
slice":

  lst[slice(item)]

but it seems like overkill. Perhaps:

  lst.after(item)

would be clearer? Or is this such a special operation, that I should
just "move on" <wink>?

-- bjorn





More information about the Python-list mailing list