Convert a sequence of bits to a bit-string

te509 at york.ac.uk te509 at york.ac.uk
Sat Dec 15 11:39:32 EST 2007


First of all I'd like to thank you all for your advices. Before I check all 
your hints I want to clarify what I'm trying to do. The question says 
"write a function that takes a sequence of bits as an input and return how 
many 1s are in the sequence", nothing more. This is quite simple for string 
inputs but tricky for "number inputs". I've notice that if I try to convert 
a number starting with 0 to a string using str(), then I take a string 
representing another number (probably converted to decimal). So what I want 
to do is to write a generic version of a function that takes as an input a 
sequence of 1s and 0s in any format. The only way I can think to achieve 
that is by converting the "number inputs" to a string and then using the 
count() function. Thomas




More information about the Python-list mailing list