Thursday, September 12, 2019

Welcome to the float zone...

Consider a REPL with two tuples, a and b.

>>> type(a), type(b)
(<type 'tuple'>, <type 'tuple'>)
>>> a == b
True


So far, so good.  But let's dig deeper...

>>> a[0] == b[0]
False


The tuples are equal, but their contents is not.



>>> a is b
True





In fact, there was only ever one tuple.
What is this madness?

>>> a
(nan,)


Welcome to the float zone.

Many parts of python assume that a is b implies a == b, but floats break this assumption.  They also break the assumption that hash(a) == hash(b) implies a == b.

>>> hash(float('nan')) == hash(float('nan'))
True


Dicts handle this pretty elegantly:

>>> n = float('nan')
>>> {n: 1}[n]
1


>>> a = {float('nan'): 1, float('nan'): 2}
>>> a
{nan: 1, nan: 2}

37 comments:

  1. Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. You’re doing a great job Man learn Python Online Course

    ReplyDelete
    Replies
    1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai

      Delete
  2. Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective. Thank you and good luck for the upcoming articles Python Programming Training

    ReplyDelete
  3. Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. You’re doing a great job Man learn Python Online Course

    ReplyDelete
  4. https://csnip2020.blogspot.com/2020/07/python-installation-steps.html?showComment=1636616273329#c834529903571727403

    ReplyDelete
  5. This post is really helpful because i was searching that kind of post that you posted and i am really happy and suggest you to read Dissertation Writing Services uk

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. I am not a programmer, but I know that it is helpful for beginners. So, I must say that this is a nice guide for computer programmers. They can learn from such blogs and enhance their programming skills. Same as students can enhance their academic writing skills by getting in touch with cheap dissertation writing services.

    ReplyDelete
  8. that is the finish of this article. Here you will locate some web pages that we believe you’ll enjoy, just click the links ove

    온라인카지노사이트
    온라인카지노
    카지노사이트

    ReplyDelete
  9. Howdy just wanted to give you a quick heads up.
    The text in your post seem to be running off
    the screen in Opera. I’m not sure if this is a format issue or something to do
    with browser compatibility but I thought I’d post
    to let you know. The design look great though! Hope you get the problem
    fixed soon. Cheers


    카지노사이트
    안전카지노사이트
    카지노사이트홈

    ReplyDelete
  10. Pretty! This was an extremely wonderful article. Thanks for
    supplying this info.



    스포츠토토
    메이저사이트 목록
    먹튀검증

    ReplyDelete
  11. Awesome write-up. I am a regular visitor of your site and appreciate you taking the time to maintain the excelent site.i will be a frequent visitor for really long time


    스포츠토토티비
    스포츠중계
    토토사이트


    ReplyDelete
  12. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! ยูฟ่า168

    ReplyDelete
  13. Nice post love it check my site for fast Satta King we provide superfast and all time result Sattaking

    ReplyDelete
  14. İnstagram takipçi satın al! İnstagram takipçi sitesi ile takipçi satın al sende sosyal medyada fenomen olmaya bir adım at. Sende hemen instagram takipçi satın almak istiyorsan tıkla:

    1- takipçi satın al

    2- takipçi satın al

    3- takipçi satın al

    ReplyDelete
  15. İnsan böyle şeyler görünce mutlu oluyor

    ReplyDelete
  16. I have been checking out a few of your stories and i can state pretty good stuff. I will definitely bookmark your blog. demolition company

    ReplyDelete
  17. Hi there colleagues, its fantastic piece of writing concerning tutoringand fully defined, keep it up all the time.
    바카라
    토토사이트

    ReplyDelete
  18. Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website.
    majortotositepro2
    racesitepro2
    oncasinositenet2
    totopickpro2

    ReplyDelete
  19. Python is a general-purpose language, meaning it can be used to create a variety of different programs and isn't specialized for any specific problems. Check also about https://www.toptreeserviceharrisonburg.com/

    ReplyDelete
  20. If you are looking for the best basement waterproofing Get additional info here.

    ReplyDelete
  21. This comment has been removed by the author.

    ReplyDelete
  22. The blog was useful in knowing about book life.Excellent blog thanks for sharing the valuable information..it becomes easy to read and easily understand the information.Create you own project from usmatlab mini project centers in chennai

    ReplyDelete
  23. Are you looking for the best concrete contractor then check out at https://www.concreteharrisonburg.com/.

    ReplyDelete
  24. Python is an object-oriented programming language that is interpreted and interactive. Learn more about Spokane Kitchen Remodel

    ReplyDelete
  25. You have a distinguished talent in explaining things. Thanks for sharing this here. best churches in shawnee

    ReplyDelete
  26. I'm searching for a great deal of information on this theme. The article I've been searching for meanwhile is the ideal article. If it's not too much trouble, visit my site for additional total articles Mesothelioma Class Action

    ReplyDelete