I am very new to python and getting stuck in list splitting even referring to many examples in stackoverflow. What can I do if I want to split a list with the following conditions?
Task 1. Split the list like this once the items in "wordlist" were found in "datalist" collected.
Wordlist = ["Time", "date", "place",....]
output = ["A","B"]["Time","C","D","E"]["Date",.....]
Task 2. Once a specific item was found, the list would be split following by the specific word and n items included, then continue to loop over the dlist. e.g.
word, n = no. of item followed
Time, 1
Date, 2
place, 1
....
input:
datalist = ["A","B", "N", "K" , "R", "Time", "2230" , "C" , "Date" , '12/05', "E" , "F", "R", "F", "K" ,"Place", "XXXXXX", "H", "I" , "J" ]
wordlist = ["Time", "Date", "Place"]
n = [1,2,1]
output:
newlist = [["A","B", "N", "K" , "R"] ,["Time", "2230"],[ "C"], [ "Date" , '12/05',"E"][ "F", "R", "F", "K" ], ["Place", "XXXXXX"], ["H", "I","J"] ]
This is my referred example solving task-1 partially while not for task-2: Python spliting a list based on a delimiter word