Question on lists

Elaine Jackson elainejackson7355 at home.com
Wed Jul 28 05:17:41 EDT 2004


If x is the given sequence, then
[x[i] for i in filter(lambda i: i==0 or x[i-1]<>x[i], range(len(x)))]
is what you want.

"Kristofer Pettijohn" <kristofer at cybernetik.net> wrote in message
news:41071cfe$0$60648$d5a6236f at newsreader.cybernetik.net...
| My question is about lists:
|
| Is there a way to remove duplicate items from a list that are
| next to each other?
|
| Example...
|
| Performing the operation on ['a', 'b', 'c', 'c', 'd', 'd', 'd', 'e']
| will return ['a', 'b', 'c', 'd', 'e']
|
| Performing the operation on ['a', 'b', 'c', 'c', 'd', 'c', 'd', 'e']
| will return ['a', 'b', 'c', 'd', 'c', 'd', 'e']
|
| I'm guessing there is probably nothing internal that will do it, so
| I may have to write something on my own - just thought I'd check
| first ;)
|
| Thanks!
|
| --
| Kristofer Pettijohn
| kristofer at cybernetik.net





More information about the Python-list mailing list