XORing long strings opimization?

Skip Montanaro skip at pobox.com
Tue Nov 4 17:43:08 EST 2003


    Noen>   alist = [chr(x ^ y) for x in ord1 for y in ord2]

    Noen> This creates a way too big list... Im not familiar with two for
    Noen> loops in one, so I cant see whats wrong :(

Try:

    alist = [chr(x ^ y) for (x, y) in zip(ord1, ord2)]

Your listcomp nests two for loops.  You need to iterate over both ord1 and
ord2 at the same time.

Skip





More information about the Python-list mailing list