寻找对称词

两个单词,如果其中一个是另一个的反向序列,则称它们为”反向对“。
比如,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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值