I would like to use 3 lists as arguments of a function. Maybe my entire logic is wrong on this, but what I'm trying to do is use two lists to create the iterators to parse the third list. The order is important, so the first element of the first and second list would give the first and last index etc.
My code gives only the first sublist, when of course I would like to have all of them.
A=[1, 3, 4, 6]
B=[3, 8, 5, 8]
C=['A', 'B','C', 'D', 'E', 'A', 'B', 'A', 'D']
def newlists(entirelist, initiating, terminating):
for initindex in initiating:
for termindex in terminating:
parsed_list = entirelist[initindex:termindex]
return parsed_list
all_sublists = newlists(C, A, B)
I need the following output or something similar to obtain the sublists:
all_sublists = [['B','C'],['D','E', 'A', 'B', 'A'],['E'],['B','A']]
parsed_list = []at the beginning of your function and then, instead ofparsed_list = entirelist[initindex:termindex]use thisparsed_list.append(entirelist[initindex:termindex])