31.03.20 20:15, Nadav Wexler пише:
Hi,
That is my first post here, I hope it's the right place for it.
so I was using some dicts had the following code:
env = dict(t for t in os.environ.items() if 'SUBSTRING' not in
t[0])
and I thought: It could have really been nice if i could do:
env = dict(t for t in os.environ.items() if 'SUBSTRING' not in
t.key)
now I see that environ is not exactly a dict, but i think this is useful
for all dictionary types. on the other hand, dicts are everywhere and
i'm not sure about the performance impact of this for those that just
ignore the access by attribute.
of course, a matching t.value must be in place as well. ;)
I would have opened a PR just to try out, but I feel this is so in the
core that I'd first like to hear some comments.
I was searching if anyone else had this idea before but couldn't find
anything.
This idea was proposed multiple times and was rejected. Python is
optimized for raw tuples, it is one of most important type. Many
operations with tuples are much faster than operations with named tuples
(including creating and destroying). Tuples emitted by dict.item() (an
enumerate(), and zip()) are usually short-living and produced in mass.
So replacing tuples with named tuples would harm a lot of code which do
not need attribute access.
_______________________________________________
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/VRVLQHMKFMVEC4T7VN5QEVSFGPEZWG7P/
Code of Conduct: http://python.org/psf/codeofconduct/