On 08.06.16 02:03, Nick Coghlan wrote: > That said, it occurs to me that there's a reasonably strong > composability argument in favour of a view-based approach: a view will > work with operator.itemgetter() and other sequence consuming APIs, > while special methods won't. The "like-memoryview-but-not" view type > could also take any bytes-like object as input, similar to memoryview > itself. Something like: class chunks: def __init__(self, seq, size): self._seq = seq self._size = size def __len__(self): return len(self._seq) // self._size def __getitem__(self, i): chunk = self._seq[i: i + self._size] if len(chunk) != self._size: raise IndexError return chunk (but needs more checks and slices support). It would be useful for general sequences too.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4