[Tutor] Duplicate items in list

Manprit Singh manpritsinghece at gmail.com
Sun Oct 11 04:01:54 EDT 2020


Dear Sir ,

I have done an experiment in the shell . which clearly proves  that  size
in Byte of None and a new instance of object ( ) are the same . Kindly have
a look .
import sys
>>> sys.getsizeof(None)
16
>>> x = object()
>>> sys.getsizeof(x)
16
>>> sys.getsizeof(x)
16

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

Regards
Manprit singh

On Sun, Oct 11, 2020 at 1:25 PM Alan Gauld via Tutor <tutor at python.org>
wrote:

> On 11/10/2020 03:40, Manprit Singh wrote:
>
> > 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
> The downside to object() is that it is comparatively expensive. It
> constructs a new instance of object which consumes more memory than
> None(a singleton instance) and is slower. That's why the normal
> sentinel/initializer value in Python is None.
>
> But it does run the risk, as in this case, that the data could
> contain none. So in that scenario object() would be a more reliable
> option.
>
> --
> 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
>
>
> _______________________________________________
> 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