[Tutor] Duplicate items in list

Alan Gauld alan.gauld at yahoo.co.uk
Sat Oct 10 06:23:29 EDT 2020


On 10/10/2020 05:41, navin ray wrote:

> provide solution to the same problem using very simple code (I.e without
> using any built in functions) so that even a noob like me could understand.

It is almost impossible to write code without using the
built in functions. They are part of the language without
which almost every task becomes impossible.

If however, you mean without using the standard library - which
is also part of the language, albeit not part of its
definition -  then that is possible and may help you understand
the principle. But you should understand that not using the
library would be considered bad practice and could, in
an interview situation, be considered a fail.

> I am sorry if my suggestions is not relevant to the mailing list.

It is completely relevant, and helping people understand basic
programming principles is part of what this list is for.

IMHO The best solution posted so far that does not use the
library is the one by Dennis Beiber (slightly modified for
clarity):

data = [3, 3, 5, 5, 5, 6, 6, 6, 5, 9, 3, 3, 3, 5, 5]
previous = None
for item in data:
    if item != previous:
	print(item)
	previous = item

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list