3 ms·
I don't get it. Why would I use a view instead of the dictionary itself?
by te 14y ago
I don't get it. Why would I use a view instead of the dictionary itself?
- e12e 14y agohttp://stackoverflow.com/questions/340850/python-3-0-dict-methods-return-views-why http://stackoverflow.com/questions/340850/python-3-0-dict-me... Views are lighter than a full copy of a list, yet behaves like a list (eg: supports `key in view`). [edit] Also, this seems to be the relevant PEP: http://www.python.org/dev/peps/pep-3106/ http://www.python.org/dev/peps/pep-3106/
- andreasvc 14y agoIt's not meant as a replacement; views form the new implementation of the keys(), values(), and items() methods in Python 3. The have been made available in Python 2 as viewkeys() etc. As said, they have the advantage of providing set operations (e.g., intersection with the keys of another dictionary), and they are more efficient than keys() or iterkeys(), because they have less overhead.