title: python- searching dictionary sublists; converting dictionary keys to values
body: <p>Say I have the following dictionary (the one I'm using is much, much larger):</p>
  
  <pre><code>dict1={1:["item", "word", "thing"], 2:["word", "item"], 3:["thing", "item", "item"]}
  </code></pre>
  
  <p>and have every word used in the dictionary stored in a list:</p>
  
  <pre><code>all_words=["item", "word", "thing"]
  </code></pre>
  
  <p>I want to run each word of the list through the dictionary sublists, and return the keys for all sublists in which they are found, storing them in tuples. So I want to get:</p>
  
  <pre><code>dict2={"item":(1, 2, 3), "word":(1, 2), "thing":(1, 3)}
  </code></pre>
  
  <p>heres what I have:</p>
  
  <pre><code>dict2={}    
  for word in all_words:
      for key, sublist in dict2.items():
          for word in sublist:
              if word not in sublist:
                  dict2[word]=dict2[word]+key
              else:
                  dict2[word]=key
  </code></pre>