题意:给两个长度相等的0,1字符串,在相同的位置的两个字符不同就输出1,否则输出0.
比如:
1010100
0100101
就输出:
1110001
代码:
print ''.join("10"[i==j] for i,j in zip(raw_input(),raw_input()))
join()函数的用法
就是把一个list中所有的串按照你定义的分隔符连接起来,比如:
list = ['a','b','c']
sep = '|'
join(list,sep)的结果就是a|b|c
>>> import string
>>> list=['abc','cde','jhjh']
>>> sep = '|'
>>> string.join(list,sep)
'abc|cde|jhjh'
>>> print string.join(list,sep)
abc|cde|jhjh
也可以这样:
>>> str = 'goujinping'
>>> ','.join(str)
'g,o,u,j,i,n,p,i,n,g'
>>> print ','.join(str)
g,o,u,j,i,n,p,i,n,g
>>>
关于split()函数的用法:
join()函数是用来连接字符串,而split()函数是用来拆分字符串。例如:
>>> list = ['my','name','is','goujinping']
>>> print list
['my', 'name', 'is', 'goujinping']
>>> print ' '.join(list)
my name is goujinping
>>> print '_'.join(list)
my_name_is_goujinping
>>> str = '_'.join(list)
>>> print str
my_name_is_goujinping
>>> str.split('_')
['my', 'name', 'is', 'goujinping']
>>> print str
my_name_is_goujinping
>>>