Convert a sequence of bits to a bit-string
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sat Dec 15 20:33:27 EST 2007
On Sat, 15 Dec 2007 16:46:38 -0800, Dennis Lee Bieber wrote:
> ... this becomes trivial... So trivial I'm going to include a solution,
> even though it is a homework assignment...
>
>>>> inp = raw_input("Enter the sequence of 1 and 0: ") print inp
> 1001101011101011101
>>>> print "The count is %s" % len(
> ... [c for c in inp if c == "1"] )
> The count is 12
*cough*
It's even more trivial than that.
>>> '1001101011101011101'.count('1')
12
--
Steven
More information about the Python-list
mailing list