Python 我已经给出了通过for循环访问嵌套列表,但我可以';结果如何?

Python 我已经给出了通过for循环访问嵌套列表,但我可以';结果如何?,python,nested-lists,string-comparison,list-manipulation,string-iteration,Python,Nested Lists,String Comparison,List Manipulation,String Iteration,我需要检查列表中是否存在搜索元素, 但我无法将“搜索”与列表元素进行比较, 搜索是用户输入的移动电话号码,用于搜索patientsList,patient,search?同意,很难说,如果您没有提供所需的信息,即patientsList在Python上读取文档以获取循环,请添加虚拟变量值,为什么要循环patient,为什么patient不是一门课instance@Shubham尝试以下操作:用于Patients列表中的患者:如果搜索==患者[1]:。创建一个患者类,以提高可读性和可维护性。使用列

我需要检查列表中是否存在搜索元素, 但我无法将“搜索”与列表元素进行比较,

搜索是用户输入的移动电话号码,用于搜索
patientsList
patient
search
?同意,很难说,如果您没有提供所需的信息,即
patientsList
在Python上读取文档以获取循环,请添加虚拟变量值,为什么要循环
patient
,为什么
patient
不是一门课instance@Shubham尝试以下操作:
用于Patients列表中的患者:如果搜索==患者[1]:
。创建一个
患者
类,以提高可读性和可维护性。使用列表很快就会让你痛苦不堪,它会直接影响到其他人loop@Shubham
else
循环?Smurphy您忘记了
中断
中添加的中断,如果
只对第一个病历有效,当我搜索第二个病历时,它会转到其他循环,这是什么意思?您是否希望能够搜索多次,但当前的解决方案只允许一次搜索?
patientsList=[['sagar','9856782311'],['mahsh','7865423158']]  
patient=['mahsh','7865423158']


search=input("Enter mobile number of patient to search")


  for i in patientsList:
        for j in patient:
            if search==patientsList[i][j]:
                print("required patient is")
                print(patient)
                print( "is Appointed")
                break
            else:
                print("Not appointed")
patientsList = [['sagar','9856782311'],['mahsh','7865423158']]

search = input("Enter mobile number of patient to search: ")    

for patient in patientsList:
    '''
    patient looks like this ['sagar','9856782311']
    patient[0] is the name
    patient[1] is the phone number
    '''
    if search == patient[1]:
        print("Required patient is")
        print(patient)
        print("is Appointed")
        break