title: wrong output in matching elements of a list of list in python
body: <p>I have a list of list in python whose sample data looks like this:</p>
  
  <pre><code>list_of_list = = [['AB2768', 'New York City', '25.0'], ['AB1789', 'San Francisco', '38.0'], ['AB6783', 'Chicago', '7.0'], ['AB2897', 'New York City', '30.0']]
  </code></pre>
  
  <p>What I have is that I am passing two parameters to my function - <code>id</code>, <code>city</code>. In my function I am matching if bot the parameters match then return the third value else return <code>0</code>. Here is my code so far:</p>
  
  <pre><code>def match_records(id, city):
      list_of_list = [['AB2768', 'New York City', '25.0'], ['AB1789', 'San Francisco', '38.0'], ['AB6783', 'Chicago', '7.0'],['AB2897', 'New York City', '30.0']]
  
  
      enrollment = ''
  
      print("searching for id- " + str(id))
      print("searching for city- " + str(city))
      for idnum, cityname, val in list_of_list:
          print(idnum + ', ' + cityname + ', ' + val)
          if str(idnum.strip()) != '' and str(id.lower().strip()) != str(idnum.lower().strip()) and str(
                  city.lower().strip()) not in str(cityname.lower().strip()):
              print('either id is empty or id not found or city not found')
              flag = 1
  
          else:
              print('Found a mactch')
              flag = 0
              enrollment = val
              break
  
      return (flag == 0, enrollment)
  </code></pre>
  
  <p>If I do <code>print(match_records('AB2768', 'San Francisco'))</code> the ideally I should get <code>False</code> as <code>AB2768</code> and <code>San Francisco</code> are not in same list but I am getting <code>True</code>. In fact if either of the two inputs are correct its returning <code>True</code>. I know the error is somewhere in my <code>if</code> logic but I am unable to guess what it is. What is the mistake here?</p>