having trouble doing some email text munging. I have participant sign ups in a list like this:
body=['Study: Study 1', 'Date: Friday, March 28, 2014 3:15 PM - 4:00 PM',
'Location: Some Place','Participant: John Doe','Study: Study 1',
'Date: Friday, March 28, 2014 4:00 PM - 4:40 PM',
'Location: Some Place','Participant: Mary Smith']
I'm new to using python, so I'm not sure if there a specific name for the operation I want. Practically, what I want is to take the list items with the 'Participant:
tag, remove that tag, and split the names up into separate list items for first and last names. So, something like this:
body=['Study: Study 1', 'Date: Friday, March 28, 2014 3:15 PM - 4:00 PM',
'Location: Some Place','John' ,'Doe']
I've tried using a list comprehension similar to here:
[item.split(' ')[1:] for item in body if re.match('Participant:*', item)]
which gives me back a nested list like this:
[['John', 'Doe'],['Mary','Smith']]
But, I have no idea how to make those nested lists with the first and last names into single list items, and no idea how to insert them back into the original list.
Any help is much appreciated!