Python 3.x 如何在我的列表(文本文件内)中搜索电话号码

Python 3.x 如何在我的列表(文本文件内)中搜索电话号码,python-3.x,Python 3.x,这是我的文本文件: ["Last_name", "Name", "birth date", "address", "xx xx xx xx xx"] ["Last_name", "Name", "birth date", "address", "xx xx xx xx xx"] 这就是我的代码: with open("repertoire.txt","r") as rep: liste = list(rep) print(len(liste)) for l

这是我的文本文件:

["Last_name", "Name", "birth date", "address", "xx xx xx xx xx"]
["Last_name", "Name", "birth date", "address", "xx xx xx xx xx"]
这就是我的代码:

with open("repertoire.txt","r") as rep:
      liste = list(rep)
      print(len(liste))

      for l in range(len(liste)):
           if len(liste[l][4])==10 or len(liste[l][4])==14:
           res.append(liste[l])
           print("\n","Voici la liste de toute les personnes disposent d'un numéro de téléphone: ", res,"\n")

我希望程序将插入电话号码的行发回,但我不断收到“超出范围”错误。

您的文本文件是否实际包含
[]
字符?因为,如果是这样的话,我认为列表(rep)
不会像你认为的那样。你的
print(len(liste))
向你显示了什么?是的,它显示了(5)这是文本文件
list(rep)
中我的行总数。当我需要删除行时,它可以正常工作,但当我在我的行中查找电话号码时,它就不能正常工作了。你在哪里收到这个“超出范围”的错误?哪一行?“print(liste[l][4]、len(liste[l][4])是否显示您所期望的内容?这是错误消息:如果len(liste[l][4])==10或len(liste[l][4])==14:索引器:字符串索引超出范围