Algorithm help per favore

Peter Hansen peter at engcorp.com
Wed Jun 18 14:10:03 EDT 2003


David Eppstein wrote:
> 
> In article <2ec1bc1c.0306180746.159679d6 at posting.google.com>,
>  wrbt at email.com (Larry) wrote:
> 
> > I need to take a list (probably 20k to 40k elements) of numbers and
> > remove consecutive duplicates. Non consecutive duplicates are ok.
> >
> > Example: [6,3,3,3,5,7,6,3,4,4,3] => [6,3,5,7,6,3,4,3]
> 
> >>> 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!  :-) :-)

-Peter




More information about the Python-list mailing list