xor on strings

Joshua Muskovitz joshm at taconic.net
Mon Feb 11 05:56:44 CET 2002


Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
>>> ''.join(map(max,zip('00','AA')))
'AA'
>>> ''.join(map(max,zip('00','A')))
'A'
>>> ''.join(map(max,zip('00','')))
''

Damn, I thought I had it.  :-)  Is there an variant of zip which doesn't
truncate?  BTW, this does work, provided that the input strings are the same
length, and even allows for more than two strings!

>>> s = ['abte','scrt','sdfw','cxvs']
>>> ''.join(map(max,zip(*s)))
'sxvw'

--
# Joshua Muskovitz
# joshm at taconic.net
def lyyrs(sig): return '-'.join(sig.split()+["ly y'rs"])
lyyrs('Hire me!  I need the work!')




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



More information about the Python-list mailing list