title: Reliably convert comma/semi-colon separated list of "last, first, last, first," names
body: <p>I have a large list of names, with the entries that contain multiple names being separated by either comma or semi-colon, or even occasionally not. For instance:</p>
  
  <pre><code>First Last
  Last, First
  Last, First, A.
  Last, First Middle
  Last, First, Last, First A., Last, First, Ph.D, Last, First, M.D., Last, J. R, Last, O.
  Last, First Middle plus other names, Last, First, Jr., Last, First, Sr.
  Last, First; Last, First A.; Last, First Middle 
  First Last, First Last, First A. Last, Last, First
  </code></pre>
  
  <p>I'm trying to create a function, as I pass in each entry individually, that would reliably return a list, with everything properly ordered as "First Last" with any possible suffixes like Jr, M.D, etc. So far, from another SO question, I have:</p>
  
  <pre><code>def fix_names(names):
      if ',' in names:
          names = [b.strip() + ' ' + a.strip()
                     for a, b in zip(*[iter(names.split(','))] * 2)]
      return names
  </code></pre>
  
  <p>I'd like to end up with:</p>
  
  <pre><code>['First Last']
  ['First Last', 'First A. Last', 'First Last, Ph.D', 'First Last, Jr.'] etc
  </code></pre>
  
  <p>If I strip suffixes such as ", M.D" first and don't keep them, most of the time it works. For instance taking one example without prefixes:</p>
  
  <pre><code>Last, First, Last, First A., Last, First, Last, First, Last, J. R., Last, O.
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>['First Last', 'First A. Last', 'First Last', 'First Last', 'J. R. Last', 'O. Last']
  </code></pre>
  
  <p>Yet another case such as "Last, First A." turns out as ['First Last']. For the cases that might be "First Last, First Last", I don't necessarily mind if it's reversed since it's more rare and I can fix them later if needed. I am also processing semi-colons and commas in separate steps since I'm not sure if it's easy to split once, and then go through each value, and add to the list if a split is needed again. </p>