I have two bytearray
s:
ba1 = bytearray(b'abcdefg')
ba2 = bytearray(b'X')
How can I insert ("prepend") ba2
in ba1
?
I tried to do:
ba1.insert(0, ba2)
But this doesn't seem to be correct.
Of course I could do following:
ba2.extend(ba1)
ba1 = ba2
But what if ba1
is very big?
Would this mean unnecessary coping of the whole ba1
?
Is this memory-efficient?
How can I prepend a bytearray
?