[Tutor] Duplicate items in list

Alan Gauld alan.gauld at yahoo.co.uk
Sun Oct 11 04:18:15 EDT 2020


On 11/10/2020 09:01, Manprit Singh wrote:

> So the only downside is , it is slow ... But slowness really matters in
> this particular case ?

It's slow and uses more memory.
Neither matters in this case(although might in others).
But the other point is that it is less idiomatic than None.

None is the most commonly used value in a scenario like this.
That makes it more readable than object() where the reader a
has to stop and think why that value has been chosen.
Readability is important, more important than performance
in most cases, but less important than reliability!

So, if you are sure the list will not contain None, use None.
If there is any possibility of the list containing None
use object()

-- 
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