so many data structures and classes have functions that return a "view" of the class. What this means is that it is not independent: it changes when the class instance does even after it has been declared
example:
>>> d
{'a': 1, 'c': 3, 'b': 2}
>>> keys = d.keys()
>>> kview = d.viewkeys()
>>> keys
['a', 'c', 'b']
>>> kview
dict_keys(['a', 'c', 'b'])
>>> d['d'] = 4
>>> keys
['a', 'c', 'b']
>>> kview
dict_keys(['a', 'c', 'b', 'd'])
so as you can see, a class dict_keys
is created that is considered a "view" of the keys in the dictionary data structure because it updates as the data structure updates.
How can you make views to classes?
note:
this is not a question on dictionaries, this is a question on how to create "views" for any type of class. numpy arrays have an attribute t
, which is simply a view on the same array, just transposed.