Re: [Tutor] Eliminating consecutive duplicates in a list

2009-06-18 Thread Kent Johnson
On Thu, Jun 18, 2009 at 9:15 AM, karma wrote: > I was playing around with eliminating duplicates in a list not using > groupby. From the two solutions below, which is more "pythonic". > Alternative solutions would be welcome. But why not use groupby()? That seems much clearer to me: In [1]: from

Re: [Tutor] Eliminating consecutive duplicates in a list

2009-06-18 Thread Dave Angel
karma wrote: I was playing around with eliminating duplicates in a list not using groupby. From the two solutions below, which is more "pythonic". Alternative solutions would be welcome. Thanks x=[1,1,1,3,2,2,2,2,4,4] [v for i,v in enumerate(x) if x[i]!=x[i-1] or i==0] [x[i] for i in range(l

Re: [Tutor] Eliminating consecutive duplicates in a list

2009-06-18 Thread Robert Berman
Whoops. That's called assuming what I read is really what I see. A good lesson in reading questions twice. I remember this from a post some time back and I remember having been intrigued by it. I used Google, and since I tend to keep extensive notes, the solution I found is not uniquely mine, but

Re: [Tutor] Eliminating consecutive duplicates in a list

2009-06-18 Thread Emile van Sebille
On 6/18/2009 7:23 AM karma said... Hi Robert, Thanks for the link. However, I am looking for eliminating consecutive duplicates rather than all duplicates - my example wasn't clear, apologies for that. x=[1,1,1,3,2,2,2,4,4,2,2] [1 ,3 ,2 ,4 ,2 ] Something like [ ii for ii,jj in zip(x,x[1:]+[

Re: [Tutor] Eliminating consecutive duplicates in a list

2009-06-18 Thread karma
Hi Robert, Thanks for the link. However, I am looking for eliminating consecutive duplicates rather than all duplicates - my example wasn't clear, apologies for that. x=[1,1,1,3,2,2,2,4,4,2,2] [1 ,3 ,2 ,4 ,2 ] 2009/6/18 Robert Berman : > This might help: http://code.activestate.com/recipes/525

Re: [Tutor] Eliminating consecutive duplicates in a list

2009-06-18 Thread Robert Berman
This might help: http://code.activestate.com/recipes/52560/ Robert On Thu, 2009-06-18 at 15:15 +0200, karma wrote: > I was playing around with eliminating duplicates in a list not using > groupby. From the two solutions below, which is more "pythonic". > Alternative solutions would be welcome. >

[Tutor] Eliminating consecutive duplicates in a list

2009-06-18 Thread karma
I was playing around with eliminating duplicates in a list not using groupby. From the two solutions below, which is more "pythonic". Alternative solutions would be welcome. Thanks x=[1,1,1,3,2,2,2,2,4,4] [v for i,v in enumerate(x) if x[i]!=x[i-1] or i==0] [x[i] for i in range(len(x)-1) if i==0