标签:http os 文件 for line on ef python c
def is_pamax(name): low = 0 up = len(name)-1 while low < up: if name[low] != name[up]: return False low += 1 up -= 1 return True f = open("D:/names.txt") max_length = 0 for line in f: name = line.strip() if is_pamax(name): temp_length = len(name) if temp_length > max_length: max_length=temp_length print max_length f.close() # maxlength=8 f = open("D:/names.txt") for line in f: name = line.strip() if is_pamax(name): if 8 == len(name): print name f.close()
下载并遍历 names.txt 文件,输出长度最长的回文人名。
标签:http os 文件 for line on ef python c
原文地址:http://my.oschina.net/u/1431368/blog/305800