title: Simplest way to convert char offsets to word offsets
body: <p>I have a python string and a substring of selected text. The string for example could be</p>
  <pre><code>stringy = &quot;the bee buzzed loudly&quot;
  </code></pre>
  <p>I want to select the text &quot;bee buzzed&quot; within this string. I have the character offsets i.e 4-14 for this particular string. Because those are the character level indices that the selected text is between.</p>
  <p>What is the simplest way to convert these to word level indices i.e 1-2 because the second and third words are being selected. I have many strings that are labeled like this and I would like to convert the indices simply and efficiently. The data is currently stored ina  dictionary like so:</p>
  <pre><code>data = {&quot;string&quot;:&quot;the bee buzzed loudly&quot;,&quot;start_char&quot;:4,&quot;end_char&quot;:14}
  </code></pre>
  <p>I would like to convert it to this form</p>
  <pre><code>data = {&quot;string&quot;:&quot;the bee buzzed loudly&quot;,&quot;start_word&quot;:1,&quot;end_word&quot;:2}
  </code></pre>
  <p>Thank you!</p>