On Mon, Jan 17, 2022 at 7:44 PM Paul Moore <[email protected]> wrote:
>
> On Mon, 17 Jan 2022 at 10:12, Steven D'Aprano <[email protected]> wrote:
> > That would make the creation of frozensets more efficient, possibly
> > encourage people who currently are writing slow and inefficient code
> > like
> >
> > targets = (3, 5, 7, 11, 12, 18, 27, 28, 30, 35, 57, 88)
> > if n in targets:
> > do_something()
> >
> > to use a frozenset, as they probably should already be doing.
>
> More realistically, would they not use a set already, as in
>
> targets = {3, 5, 7, 11, 12, 18, 27, 28, 30, 35, 57, 88}
> if n in targets:
> do_something()
>
> ?
>
This is very inefficient because building a set is much heavier in `n in tuple`.
We should write `if n in {3, 5, 7, 11, 12, 18, 27, 28, 30, 35, 57, 88}` for now.
Or we should write `_TARGETS = frozenset((3, 5, 7, 11, 12, 18, 27, 28,
30, 35, 57, 88))` in global scope and use it as `if n in _TARGETS`.
--
Inada Naoki <[email protected]>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/RAW2KG77YI5GS4AXLLFKLBR3PTVE65OA/
Code of Conduct: http://python.org/psf/codeofconduct/