On Sun, May 10, 2020 at 09:36:14PM -0700, Andrew Barnert via Python-ideas wrote:
for i in itertools.seq_view(a_list)[::2]: ...
I still think I prefer this though:
for i in a_list.view[::2]: ...
Agreed. A property on sequences would be best,
This leads to the same problem that len() solves by being a function, not a method on list and tuple and str and bytes and dict and deque and .... Making views a method or property means that every sequence type needs to implement it's own method, or inherit from the same base class, and that's why in the Java world nobody agrees what method to call to get the length of an object.
Python has a long history of using protocols and optional dunders for things like this:
So if we are to have a generic view proxy object, as opposed to the very much non-generic dict views, then it ought to be a callable function which, *if necessary*, delegates to a `__view__` dunder.