lina wrote:
Hi,

How to remove the coming duplication,

Here I wrote one (not working):


a=['2', '5', '7', '5', '5']
[...]
I wish to get a is [2,5,7,5]

just remove the coming duplication, not unique the list.

a = [2, 5, 7, 5, 5]
b = a[0:1]  # slice of the first item only
for x in a[1:]:  # slice of the second item to the end
    if x != b[-1]:
        b.append(x)


gives b = [2, 5, 7, 5] as requested.



--
Steven
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to