Algorithm help per favore

David Eppstein eppstein at ics.uci.edu
Wed Jun 18 12:40:31 EDT 2003


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]

-- 
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