Il giorno gio 8 dic 2022 alle ore 06:37 Andrea D'Amore <a...@d-amo.re> ha scritto:
> On Wed, 7 Dec 2022 at 18:40, Marco De Paoli <depao...@gmail.com> wrote: > > Mi viene il dubbio che nel confronto tra tuple venga valutata una > identità tra oggetti... ma, al momento, non riesco ad approfondire la > questione > > Il confronto tra sequenze usa `is` come scorciatoia invece di `==`. > > https://docs.python.org/3/reference/expressions.html#comparisons > """Sequences compare lexicographically using comparison of > corresponding elements. The built-in containers typically assume > identical objects are equal to themselves. That lets them bypass > equality tests for identical objects to improve performance and to > maintain their internal invariants.""" è vero, grazie in realtà la cosa è anche un po' più subdola di così, infatti istanze diverse di nan ... sono diverse! >>> import math >>> math.nan is math.nan # OK, identity True >>> float("nan") is float("nan") # ... OOOK, different instances! False Dalla regia (grazie CM) mi segnalano questo riferimento: https://bugs.python.org/issue21873#msg221608 e questo esempio: >>> set([nan, nan]) {nan} time: 19 ms (started: 2022-12-07 19:14:16 +01:00) >>> set([float('nan'), float('nan')]) {nan, nan} time: 8.54 ms (started: 2022-12-07 19:14:34 +01:00) bye, M
_______________________________________________ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python