On 26-3-2015 0:14, kai.pet...@gmail.com wrote:
> On Tuesday, 24 March 2015 20:14:06 UTC-7, otaksoft...@gmail.com  wrote:
>> I have a list containing 9600 integer elements - each integer is either 0 or 
>> 1.
>>
>> Starting at the front of the list, I need to combine 8 list elements into 1 
>> by treating them as if they were bits of one byte with 1 and 0 denoting bit 
>> on/off (the 8th element would be the rightmost bit of the first byte).
>>
>> The end result should be a new list that is 8 x shorter than the original 
>> list containing integers between 0 and 255.
>>
>> Speed is not of utmost importance - an elegant solution is. Any suggestions?
>>
>> Thanks for all input,
>> Kai
> 
> 
> 
> The list comes from PILLOW:
> 
> getdata #
> 
> im.getdata() => sequence
> 

Don't you want to use Image.tobytes() instead? Or, Image.save() directly if you 
want to
store the image somewhere else perhaps?
In other words, what are you going to do with the -internal- data returned from 
getdata,
perhaps you don't even want to call it, and skip dealing with the raw pixel bits
altogether...

Irmen

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to