title: for loop with set: key
body: <p>I get a Keyerror when doing a for loop on a set of int values. </p>
  
  <p>Here is the code: </p>
  
  <pre><code># groupes : dict[str:set[int]]
  groupes = {'cinephiles':{802,125,147,153}, \
  'travaux manuels':{125,802,153}, \
  'cuisine':{153,147,802}, \
  'sport':{153,538,802}}
  
  # This first function helps me for the second one
  
  def proximite_groupes(group, hobby_1, hobby_2):
      """ 
         dict[str:set[int]] * str * str -&gt; float
      """
  
      # intersection_set : set[int]
      intersection_set = set()
      # union_set : set[int]
      union_set = set()
  
      # cle : int
      for cle in group[hobby_1]:
          if cle in group[hobby_2]:
              intersection_set.add(cle)
  
  
      for cle in group[hobby_1]:
          if cle not in union_set:
              union_set.add(cle)
  
      for cle in group[hobby_2]:
          if cle not in union_set:
              union_set.add(cle)
  
  
      return len(intersection_set) / len(union_set)
  
  
  def fusion_groupes(group):
      """ 
         dict[str:set[int]] -&gt; dict[str:set[int]]
      """
  
      # similarite_max : int
      similarite_max = 0.0
      # str_1 : str
      # str_2 : str
      # str_1_final : str
      str_1_final = ''
      str_2_final = ''
      # str_1_final : str
      # str_final : str
      str_final = ' '
      # final_dict : dict[str:set[int]]
      final_dict = group
      # intersection_set : set[int]
      intersection_set = set()
  
      for str_1 in group:
          for str_2 in group:
              if str_1 != str_2:
                  if proximite_groupes(group, str_1, str_2) &gt; similarite_max:
                      similarite_max = proximite_groupes(group, str_1, str_2)
                      str_final = str_1 + '_' + str_2
                      str_1_final = str_1
                      str_2_final = str_2
  
      del final_dict[str_1_final]
      del final_dict[str_2_final]
  
      # Creation ensemble union
      for cle in group[str_1_final]:
          if cle in group[str_2_final]:
              intersection_set.add(cle)
  
      final_dict[str_final] = intersection_set
  
      return final_dict
  </code></pre>
  
  <p>The purpose of the function is a little bit hard to difficult, but my problem here is:</p>
  
  <pre><code>File "&lt;input&gt;", line 1, in &lt;module&gt;
    File "&lt;input&gt;", line 261, in fusion_groupes (note that the line would not be the same for you because my program has more lines)
  KeyError: 'cuisine' 
  </code></pre>
  
  <p>(but one time it's 'cuisine', the other time its 'cinephiles', or 'sport', ...</p>