title: How should I loop through a Python 2.6 dict and efficiently check another dict to see if the same key exists?
body: <p>In Python 2.6, I have a dict of a student's coursework that I am looping through, then checking against a second dict of course requirements to see if the student has satisfied those requirements. My code is starting to get a bit ugly though, as I'm currently looping through a FOR loop of the requirement dict and checking the student's coursework dict for each listed requirement. This results in looping multiple times through the same dict since some of the loops depend on if the student is of a certain major, enrolled in one school or another, and so on. So each time I enter the loop it's to evaluate the same data on differing "IF" clauses.</p>
  
  <p>So it occurs to me that there has to be a better way, right? I fear my page load time is going to grow exponentially as I add loops through the same dict(s) multiple times for the same page load (not to mention it becoming a maintenance nightmare). My hope is there is a way to do something like:</p>
  
  <pre><code>if dict1{key} in dict2{key}:
      if other dependent conditions are True (e.g. non_business_major, etc):
          do something, set a var to True, etc.
  </code></pre>
  
  <p>EDIT:...adding sample of dicts.</p>
  
  <pre><code># -------------------------------------------
  acad_hist_condensed: [{'semester_hours_passed': u'2', 'fos': u'MUS', 'grade': u'B', 'topic_number': u'0', 'ccyys': u'20072', 'compressed_hist_crse_id': u'MUS 201J0', 'crse_number': u' 201J'}, {'semester_hours_passed': u'2', 'fos': u'MUS', 'grade': u'C', 'topic_number': u'0', 'ccyys': u'20079', 'compressed_hist_crse_id': u'MUS 201K0', 'crse_number': u' 201K'},...
  
  # -------------------------------------------
  course_reqs: [{'_created_by': u'kre86', '_updated': datetime.datetime(2014, 3, 24, 8, 56, 19), 'topic_nbr': u'0', 'requirement_group': u'Prereq', 'fos': u'FIN', 'crse_nbr': u' 320F', 'program_id': 1237L, 'major_group': u'Non-Bus', 'crse_title': u'', '_updated_by': u'kre86', '_created': datetime.datetime(2014, 3, 24, 8, 56, 19), 'id': 2L}, {'_created_by': u'kre86', '_updated': datetime.datetime(2014, 3, 24, 8, 57, 2), 'topic_nbr': u'0', 'requirement_group': u'Prereq', 'fos': u'FIN', 'crse_nbr': u' 357', 'program_id': 1237L, 'major_group': u'Bus', 'crse_title': u'', '_updated_by': u'kre86', '_created': datetime.datetime(2014, 3, 24, 8, 57, 2), 'id': 3L}, 
  </code></pre>
  
  <p>EDIT: ...forgot to add an example of what I'm doing now. This is a fraction of the number of times I do this type of loop.</p>
  
  <pre><code># -------------------------------------------
  # look for non-business major recommended
  if course_req['requirement_group'] == 'Recommended'\
          and course_req['major_group'] == 'Non-Bus'\
          and is_business_student is False:
      for hist in acad_hist_condensed:
          if hist['compressed_hist_crse_id'] == compressed_course_req:
              non_bus_recomm_met = True
              non_bus_recomm_crse = hist
  </code></pre>
  
  <p>Any help would be appreciated. Thanks</p>