On Wed, Oct 14, 2009 at 10:48 PM, Wayne <[email protected]> wrote: > Using zip is redundant for me, this is what my function looks like now: > def crypt(msg, mask): > m = itertools.cycle(mask) > word = '' > for l in msg: > word += chr(ord(l) ^ ord(m.next())) > return word
With zip() and a generator expression you can write it as def crypt(msg, mask): mask = itertools.cycle(mask) chars = zip(msg, mask) return ''.join(chr(ord(l) ^ ord(m)) for l, m in chars) which could be reduced to a one-liner if you like. Kent _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
