title: How to search a partial text in dict?
body: <p>I have a dictionary and would like to be able to search with a partial variable and return a text.</p>
  
  <pre><code>df = pd.read_csv('MY_PATH')
  d = defaultdict(lambda: 'Error, input not listed')
  d.update(df.set_index('msg')['reply'].to_dict())
  d[last_msg()]
  </code></pre>
  
  <p><code>last_msg()</code> should be my partial variable, and <code>d</code> is my dictionary. </p>
  
  <p>The index on my dictionary is column <code>msg</code> from <code>df</code>.</p>
  
  <p>In column <code>msg</code> i have a sample like <code>Jeff Bezos</code>.</p>
  
  <p>In column <code>reply</code> i have a matching reply <code>Jeff Bezos is the CEO of Amazon</code></p>
  
  <p><strong>How can I search a partial value in column <code>msg</code> and return matching value from column <code>reply</code>?</strong></p>
  
  <p>I want to search just <code>Jeff</code> or just <code>Bezos</code> and get the matching reply <code>Jeff Bezos is the CEO of Amazon</code></p>
  
  <p>PS. Alternatives to <code>defaultdict</code> may also help improve the code.</p>
  
  <p>EDIT: <code>last_msg()</code> code extracts a text from selenium element.</p>
  
  <pre><code>def last_msg():
  try:
      post = driver.find_elements_by_class_name("_12pGw")
      ultimo = len(post) - 1
      texto = post[ultimo].find_element_by_css_selector(
          "span.selectable-text").text
      return texto
  except Exception as e:
      print("Error, input not valid")
  </code></pre>
  
  <p>When I print(d):</p>
  
  <pre><code>defaultdict(&lt;function &lt;lambda&gt; at 0x0000021F959D37B8&gt;, {'Jeff Bezos': 'Jeff Bezos is the CEO of Amazon', 'Serguey Brin': 'Serguey Brin co-founded Google', nan: nan})
  </code></pre>
  
  <p>When I print(df)</p>
  
  <pre><code>   Unnamed: 0           msg                            reply
  0           0    Jeff Bezos  Jeff Bezos is the CEO of Amazon
  1           1  Serguey Brin   Serguey Brin co-founded Google
  2           2           NaN                              NaN
  3           3           NaN                              NaN
  </code></pre>