Algorithm help per favore
David Eppstein
eppstein at ics.uci.edu
Wed Jun 18 14:56:27 EDT 2003
In article <3EF0AAFB.DDA5F555 at engcorp.com>,
Peter Hansen <peter at engcorp.com> wrote:
> > >>> L = [6,3,3,3,5,7,6,3,4,4,3]
> > >>> [x for x, y in zip(L, [L]+L) if x != y]
> > [6, 3, 5, 7, 6, 3, 4, 3]
>
> But this won't work if L contains a reference to L! :-) :-)
Ok, what's the quickest way to build a new object that's guaranteed
unequal to any previous object? E.g.
[x for x, y in zip(L, [lambda x:x]+L) if x != y]
There must be a better way to do this than with a lambda.
--
David Eppstein http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science
More information about the Python-list
mailing list