title: How to transform dictionary keys into a dataframe column based on the values if the values are lists
body: <p>I have a dictionary of where the keys are numbers and the values are lists of strings. I want to create a dataframe column where the column values are the dictionary keys and the key is selected base on matching the value of another column in each row to an item in the dictionary value lists. See example code below:
  Sample starting dataframe and dictionary:</p>
  <pre><code>dict_x = {1:[a], 2:[b, c, e], 3:[d, f]
  df = ['ID':[a, b, c, d, e, f]]
  </code></pre>
  <p>Desired output:</p>
  <pre><code>df = ['ID':[a, b, c, d, e, f], 'Number':[1, 2, 2, 3, 2, 3]]
  </code></pre>
  <p>I thought some sort of <code>df['Number'] = df['ID'].apply(lambda x : ???)</code> would work but I'm struggling with the conditions here, and I tried writing some for loops but ran in to issues with only the last iteration of the loop being preserved when I wrote the column.</p>