chop#
- hexrec.utils.chop(vector, window, align_base=0)[source]#
Chops a vector.
Iterates through the vector grouping its items into windows.
- Parameters:
vector (items) – Vector to chop.
window (int) – Window length.
align_base (int) – Offset of the first window.
- Yields:
list or items – vector slices of up to window elements.
Examples
>>> list(chop(b'ABCDEFG', 2)) ['AB', 'CD', 'EF', 'G']
>>> b':'.join(chop(b'ABCDEFG', 2)) b'AB:CD:EF:G'
>>> list(chop(b'ABCDEFG', 4, 3)) [b'A', b'BCDE', b'FG']