
On Mon, Jan 17, 2022 at 7:44 PM Paul Moore <p.f.moore@gmail.com> wrote:
On Mon, 17 Jan 2022 at 10:12, Steven D'Aprano <steve@pearwood.info> 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 <songofacandy@gmail.com>