'Prepending bytearray: TypeError: an integer is required
I have two bytearrays:
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?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
