[Tutor] how to remove the coming duplication

lina lina.lastname at gmail.com
Thu Nov 10 14:57:34 CET 2011


On Thu, Nov 10, 2011 at 8:48 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> 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)

               for index, b in enumerate([b_list]):
                        print(b)

how can I avoid the output not as:
['53', '76', '57']

but as
53
76
57

Thanks

>
>
> gives b = [2, 5, 7, 5] as requested.
>
>
>
> --
> Steven
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list