5 ms·
I do not see the use for this, over the standard access methods. people = { "Diane": 70, "Bob": 78, "Emma": 84 } people.ge
by matjet 4y ago
I do not see the use for this, over the standard access methods.
people = {
"Diane": 70,
"Bob": 78,
"Emma": 84
}
people.get("Bob")
# 78
The common usecase is:
for key in people.keys():
people.get(key)
vs
keys = people.keys()
# dict_keys(['Diane', 'Bob', 'Emma'])
for key in keys:
keys.mapping[key]
What is the advantage?
- ssl232 4y agoIt gives you access to the original dictionary from a view. I've not played with it yet but I guess that means you can modify it. EDIT: apparently not: >>> keys.mapping mappingproxy({'Diane': 70, 'Bob': 78, 'Emma': 84}) In this case I actually don't know what the use case is :shrug:
- mjw1007 4y agoThe rationale was here. https://github.com/python/cpython/issues/85067#issuecomment-1093874030 https://github.com/python/cpython/issues/85067#issuecomment-... It seems a bit vague: « Exposing this attribute would help with introspection, making it possible to write efficient functions that operate on dict views. »