两个单词,如果其中一个是另一个的反向序列,则称它们为”反向对“。
比如,dog,反过来是god;eye,反过来还是eye.
编写一个程序找出输入的字符串中的全部反向对。
输入
god have eye, dog also have eye. dog on the table, there is no god on the table.
输出
god<->dog
eye<->eye
on<->no
shuru = input()
sr = []
for item in shuru:
if item == ',' or item == '.' :
continue
else:
sr.append(item)
srpj =''.join(sr) .split()
l = len(srpj)
cishu = []
for i in range(0,l):
for j in range(i+1,l):
li = list(srpj[i])
lj = list(srpj[j])
lj.reverse()
if li == lj :
lii = ''.join(li)
lj.reverse()
ljj = ''.join(lj)
if cishu.count(lii) == 0 and cishu.count(ljj) == 0:
print('%s<->%s'%(lii,ljj))
cishu.append(lii)
cishu.append(ljj)
break