Reverse order of bit in repeating seqence of byte string
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Fri Jan 2 18:28:57 EST 2009
imageguy:
> I receive the byte string with the following sequence 'bgrbgrbgrbgr'
> and I would like to convert this to 'rbgrbgrbgrbg'
> FWIW, the string is created using ctypes.create_string_buffer function
MRAB:
> >>> a.tostring()
> '210543876'
That's not the required 'rbgrbgrbgrbg', but you are close to a correct
solution:
>>> from array import array
>>> s = 'bgrbgrbgrbgr'
>>> a = array("B", s) # uppercase B
>>> a[0::3], a[1::3], a[2::3] = a[2::3], a[0::3], a[1::3]
>>> a.tostring()
'rbgrbgrbgrbg'
Bye,
bearophile
More information about the Python-list
mailing list