[Tutor] how to remove the coming duplication

spawgi at gmail.com spawgi at gmail.com
Thu Nov 10 08:30:00 CET 2011


Hello,

list.remove will remove the first occurrence of the value from the list. So
the output is expected as far as Python is concerned.
May be you should think about using pop function.
Please take a look at the code below


>>> def RemoveComingDuplicates(a):
for i in range(len(a)-1):
 print i,i+1
if a[i+1] == a[i]:
a.pop(i+1)
 print a

>>> a = ['2','5','7','5','5']
>>> RemoveComingDuplicates(a)
0 1
['2', '5', '7', '5', '5']
1 2
['2', '5', '7', '5', '5']
2 3
['2', '5', '7', '5', '5']
3 4
['2', '5', '7', '5']
>>>

Hope this helps.

Thanks and Regards,
Sumod
On Thu, Nov 10, 2011 at 12:54 PM, lina <lina.lastname at gmail.com> wrote:

> >>> for i in range(len(a)):
>        if i == 0:
>                b.append(a[i])
>        if a[i]!=b[-1]:
>                b.append(a[i])
>
> This one seems work, but looks clumsy,
>
> Thanks for any suggestions that helps to improve.
>
> Best regards,
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
http://spawgi.wordpress.com
We can do it and do it better.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111110/9f490f87/attachment-0001.html>


More information about the Tutor mailing list