> [1, 2, 3][1:int(1e9)]
[2, 3]
Coming from C background the above code gives me a mini heart attack. But it seems to work. Is it guaranteed to work in any python3
? Is it as efficient as > [1, 2, 3][1:int(2)]
? Is it considered bad form as in 'prefer to use anything else before relying on this behavior'?
OK, I've probably described the problem badly. This is my code. The last access is out of bonds most of the time. Is that fine?
def cut(b: bytes, max: int) -> [bytes]:
'''Chop into pieces no longer than max bytes.'''
return [b[i:i+max] for i in range(0, len(b), max)]