判断一个文本txt里面的人名回文字符串
f=open("D:/names.txt")
def is_panlindrom_rec(name):#方法一用递归的方法
if len(name)<=1:
return True
else:
if name[0]!=name[-1]:
return False
else:
return is_panlindrom_rec(name[1:-1])
def is_panlindrom(name):#方法二
low=0
high = len(name) - 1
while low <high:
if name [low] !=name[high]:
return False
low +=1
high-=1
return True
for line in f:
line = line.strip()
if is_panlindrom_rec(line):
print line
f.close()