[Tutor] Duplicate items in list
Manprit Singh
manpritsinghece at gmail.com
Sat Oct 10 22:40:08 EDT 2020
Dear sir ,
I feel the use of the object() call is ok , while printing the elements of
the list without printing the consecutive duplicates .
lst = [3, 3, 5, 5, 5, 6, 6, 6, 5, 9, 3, 3, 3, 5, 5]
last = object()
for itm in lst:
if itm != last:
... print(itm)
... last = itm
Here If the List is starting from None then it is more safer to take last =
object(). Need to know why it should not be preferred ? Any specific reason
?
Regards
Manprit Singh
On Sat, Oct 10, 2020 at 11:33 PM Dennis Lee Bieber <wlfraed at ix.netcom.com>
wrote:
> On Sat, 10 Oct 2020 11:23:29 +0100, Alan Gauld via Tutor <tutor at python.org
> >
> declaimed the following:
>
> >IMHO The best solution posted so far that does not use the
> >library is the one by Dennis Beiber (slightly modified for
> >clarity):
> >
> Yeah -- I should have put more separation between the OP's "lst"
> and my
> use of "last". I used the object() call just to guard against a data set
> that started with a None itself -- which was likely being overly cautious
> for the given problem description...
>
>
> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfraed at ix.netcom.com
> http://wlfraed.microdiversity.freeddns.org/
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list