XORing long strings opimization?

Ulrich Petri ulope at gmx.de
Tue Nov 4 17:13:01 EST 2003


"Peter Otten" <__peter__ at web.de> schrieb im Newsbeitrag
news:bo8vq8$9q5$01$1 at news.t-online.com...
> Noen wrote:
>
> > Oh, didnt notice that as I wrote it. Thanks...
> > Anyway, this is how it should be.
> >
> > def XOR(s1,s2):
> >      """ XOR string s1 with s2 """
> >      output = ""
> >      # Argument check
> >      if (type(s1) and type(s2)) != type(""):
> >          raise TypeError, "Arguments are not strings"
> >      if len(s1) != len(s2):
> >          raise ValueError, "Size differs in strings"
> >      # Xoring
> >      for i in range(len(s1)):
> >          output += chr(ord(s1[i]) ^ ord(s2[i]))
> >      return output
>
> Oops, I missed one:

Therese even more ;)

> >      if (type(s1) and type(s2)) != type(""):
> >          raise TypeError, "Arguments are not strings"

i guess he meant:
> >      if  type(s1) != type("") or type(s2) != type(""):
> >          raise TypeError, "Arguments are not strings"

Ciao Ulrich






More information about the Python-list mailing list