I have looked at this:Split list into sublist based on index ranges
But my problem is slightly different. I have a list
List = ['2016-01-01', 'stuff happened', 'details',
'2016-01-02', 'more stuff happened', 'details', 'report']
I need to split it up into sublists based on the dates. Basically it's an event log but due to shitty DB design the system concats separate update messages for an event into one big list of strings. I have:
Event_indices = [i for i, word in enumerate(List) if
re.match(date_regex_return_all = "(\d+\-\d+\-\d+",word)]
which for my example will give:
[0,3]
Now I need split the list into separate lists based on the indexes. So for my example ideally I want to get:
[List[0], [List[1], List[2]]], [List[3], [List[4], List[5], List[6]] ]
so the format is:
[event_date, [list of other text]], [event_date, [list of other text]]
There are also edge cases where there is no date string which would be the format of:
Special_case = ['blah', 'blah', 'stuff']
Special_case_2 = ['blah', 'blah', '2015-01-01', 'blah', 'blah']
result_special_case = ['', [Special_case[0], Special_case[1],Special_case[2] ]]
result_special_case_2 = [ ['', [ Special_case_2[0], Special_case_2[1] ] ],
[Special_case_2[2], [ Special_case_2[3],Special_case_2[4] ] ] ]