Jan-03-2019, 04:28 AM
I have a list of words and I want to get the values of all words in between the word "and" but have to account for the number of words in between "and" varies as well as the amount of ands will vary in the list
list = ['visit', 'houston', 'and', 'san', 'antonio', 'and', 'austin', 'and', 'corpus', 'christi']
needing
list[1] # for Houston
list[3:4] #for joining san antonio
list[6] #for austin
list[8:] #for joining corpus christi
here is what i have so far
list = ['visit', 'houston', 'and', 'san', 'antonio', 'and', 'austin', 'and', 'corpus', 'christi']
needing
list[1] # for Houston
list[3:4] #for joining san antonio
list[6] #for austin
list[8:] #for joining corpus christi
here is what i have so far
index_ands = [index for index, value in enumerate(list) if value == "and"] #gives the index of ands [2,5,7] andleng = len(index_ands) #gives the number of ands is 3 for ands in index_ands: #What goes here?