Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
How do I get something similar to dictionary views, but for sequences?
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
It isn't writable (but then again, neither are the dictionary views), but you might be interested in more_itertools.SequenceView.
0 comment threads