[Python-Dev] iter.index()
'Christian Stork'
python-dev-list at cstork.org
Sun Apr 18 23:12:47 EDT 2004
On Sun, Apr 18, 2004 at 10:37:28PM -0400, Raymond Hettinger wrote:
> [Christian Stork]
> > I wanted to do something like
> >
> > i = itertools.chain(list1, list2).index(elem)
>
> I'm curious about what application needed to do this.
It's for a simulation of a peer-to-peer algorithm I'm working on. The
lists are lists of peers and could potentially become _very_ large.
Therefore concatenation might not be cheap.
> > If I use the operator module it works just fine.
> >
> > i = operator.indexOf(itertools.chain(list1, list2), elem)
>
> Nice solution. It is general purpose, self-documenting, and efficient.
Thanks. :-)
--
Chris Stork <> Support eff.org! <> http://www.ics.uci.edu/~cstork/
OpenPGP fingerprint: B08B 602C C806 C492 D069 021E 41F3 8C8D 50F9 CA2F
More information about the Python-Dev
mailing list