On Mon, 17 Jan 2022 at 10:12, Steven D'Aprano <st...@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()

?

Is using a frozenset a significant improvement for that case? Because
I doubt that anyone currently using a tuple would suddenly switch to a
frozenset, if they haven't already switched to a set. Sure, there
might be the odd person who sees the release notes and is prompted by
the mention of frozenset literals to re-think their code, but that's
probably a vanishingly small proportion of the audience for this
change.

BTW, I should say that I'm actually +0.5 on the idea. It seems like a
reasonable thing to want, and if an acceptable syntax can be found,
then why not? But I doubt it's going to have a major impact either
way.

Paul
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/EYQC3PH3W24K7NTQ66KB3DL334LYDK5A/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to