title: Finding multiple common starting strings
body: <p>I have a list of strings in which one or more subsets of the strings have a common starting string. I would like a function that takes as input the original list of strings and returns a list of all the common starting strings. In my particular case I also know that each common prefix must end in a given delimiter. Below is an example of the type of input data I am talking about (ignore any color highlighting):</p>
  
  <blockquote>
  <pre><code>Population of metro area / Portland
  Population of city / Portland
  Population of metro area / San Francisco
  Population of city / San Francisco
  Population of metro area / Seattle
  Population of city / Seattle
  </code></pre>
  </blockquote>
  
  <p>Here the delimiter is <code>/</code> and the common starting strings are <code>Population of metro area</code> and <code>Population of city</code>. Perhaps the delimiter won't ultimately matter but I've put it in to emphasize that I don't want just one result coming back, namely the universal common starting string <code>Population of</code>; nor do I want the common substrings <code>Population of metro area / S</code> and <code>Population of city / S</code>.</p>
  
  <p>The ultimate use for this algorithm will be to group the strings by their common prefixes. For instance, the list above can be restructured into a hierarchy that eliminates redundant information, like so:</p>
  
  <blockquote>
  <pre><code>Population of metro area
      Portland
      San Francisco
      Seattle
  Population of city
      Portland
      San Francisco
      Seattle
  </code></pre>
  </blockquote>
  
  <p>I'm using Python but pseudo-code in any language would be fine.</p>
  
  <p><strong>EDIT</strong>
  As noted by Tom Anderson, the original problem as given can easily be reduced to simply splitting the strings and using a hash to group by the prefix. I had originally thought the problem might be more complicated because sometimes in practice I encounter prefixes with embedded delimiters, but I realize this could also be solved by simply doing a right split that is limited to splitting only one time.</p>