How do I get something similar to dictionary views, but for sequences?
+3
−0
The dictionary methods .keys(), .values(), and .items() all return view objects. Said objects reflect any changes to the underlying dictionary. This is often useful.
Is there a way to get such a view on sequences such as lists? For example, a slice-like object that, instead of copying part of a sequence, maps __getitem__
/ __setitem__
to the sliced part of the original object? I think I could implement such a thing, but if there's already an appropriate builtin or common library, I'd rather use that.
1 answer
+4
−0
It isn't writable (but then again, neither are the dictionary views), but you might be interested in more_itertools.SequenceView.
0 comment threads