Convert to binary and convert back to strings
Hendrik van Rooyen
mail at microcorp.co.za
Sat Feb 24 02:59:04 EST 2007
"Paul Rubin" <http://phr.cx@NOSPAM.invalid> wrote:
> "Hendrik van Rooyen" <mail at microcorp.co.za> writes:
> > s = 'some string that needs a bcc appended'
> > ar = array.array('B',s)
> > bcc = 0
> > for x in ar[:]:
> > bcc ^= x
> > ar.append(bcc)
> > s=ar.tostring()
>
> Untested:
>
> import operator
> s = 'some string that needs a bcc appended'
> ar = array.array('B',s)
> s += chr(reduce(operator.xor, ar))
>
Yikes! - someday soon I am going to read the docs on
what reduce does...
Won't this be slow because of the double function call on each char?
- Hendrik
More information about the Python-list
mailing list