Mar-31-2022, 04:02 AM
(This post was last modified: Mar-31-2022, 04:02 AM by deanhystad.)
Reading through this one last time I think I might know the question.
https://docs.python.org/3.2/library/stdt...ew-objects
As pointed out in his post, a view object has several interesting attributes. The most interesting to me is that it is dynamic. If you change the dictionary after making the view, the view reflects the changes. So a view is not a collection, but rather a "view" into another collection.
Quote:How do I get the values from a dict_values object?As stevendprano pointed out, dict.values() returns a view object. You can read about them here:
https://docs.python.org/3.2/library/stdt...ew-objects
As pointed out in his post, a view object has several interesting attributes. The most interesting to me is that it is dynamic. If you change the dictionary after making the view, the view reflects the changes. So a view is not a collection, but rather a "view" into another collection.
x = {1:1, 2:4, 3:9} y = x.values() print(y) x[2] = 42 print(y)
Output:dict_values([1, 4, 9])
dict_values([1, 42, 9])
According to the documentation a view object can be iterated over. You can use a view object in a for loop, in a comprehension, and pass it as an argument to list(). So if you want to treat a views object like it was a list, the easiest way is use list() to make a list.x = {1:1, 2:4, 3:9} y = list(x.values()) print(y, y[0])
Output:[1, 4, 9] 1
I still don't understand how the values will be used, but I can leave that question unanswered without too much discomfort. The pairs, triples and quadruples are all red herring. Now that noob knows how to get the values from the dictionary view he'll figure out how to use them.