Algorithm help per favore

David Eppstein eppstein at ics.uci.edu
Thu Jun 19 09:02:11 CEST 2003


In article <bcrl56$98p$1 at news.hccnet.nl>,
 anton at vredegoor.doge.nl (Anton Vredegoor) wrote:

> Nice idea, there seems to be no problem with L an empty list, but
> there would be a problem with L a tuple. However that can be
> corrected:
> 
>    [x for x,y in zip(L,L[1:]+L[:-1]) if x!=y] or list(L[:1])

Still buggy, it drops the last item whenever it's equal to the first and 
the list has two unequal items.

>>> L=[3,1,4,1,5,9,3]
>>> [x for x,y in zip(L,L[1:]+L[:-1]) if x!=y] or list(L[:1])
[3, 1, 4, 1, 5, 9]

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