title: Dynamically joining list elements based on key
body: <p>My data starts with a pandas dataframe. Then I convert the column which I am interested in into a python list and I am trying to join certain elements of that list into one based on some specific rules.</p>
  <p>My example list may look like this:</p>
  <pre><code>list_1 = ['country: US', 'firstname: John', 'displayName: A', 'JohnS123', 'address: 123 main st', 'baltimore', 'MD', '12345', 'email:jsmith@email.com']
  </code></pre>
  <p>I am looking for all the indexes that contain a ' : ' in them. <code>list_1[0]</code> contains ' : ' in it so it's okay. <code>list_1[1]</code> also contains the character so it is also okay. <code>list_1[3]</code> does not contain ' : ' so I am trying to join it with <code>list_1[2]</code> by adding a ' , ' in between them. So in the new list <code>list_1[2]</code> would look like, <code>'displayName: A, JohnS123'</code>.</p>
  <p>Additionally, I am trying to add all the indices that do not contain ' : ' to the <code>index-1</code> until the I reach the next item in the list that contains ' : '.</p>
  <p>Here's what the new list would look like after executing.</p>
  <pre><code>new_list = ['country: US', 'firstname: John', 'displayName: A, JohnS123', 'address: 123 main st, baltimore, MD, 12345', 'email:jsmith@email.com']
  len(list_1) -&gt; 9
  len(new_list) -&gt; 5
  </code></pre>
  <p>I've trying to do this by setting up different algorithms using lists, but if it can also be done through pandas I am open to both options.</p>