The testList
example represents list strings from a text file. The compareList
represents a values list from a dictionary. I want to ‘pull out’ subsets of a string AFTER the match.
# Use a set result to print "fox here!"
testList = ['quick', 'brown', 'fox', 'here!']
compareList = ['beige', 'black', 'brown']
foundList = []
result = set(testList) & set(compareList)
# <class 'set'> {'brown'}
How to use the compareList
value ‘brown’ to print the remainder of the testList
eg ['fox', 'here!']
From a resultant foundList
>Solution :
Get the index of brown
and then slice the rest of the list.
color = list(result)[0]
index = testList.index(color)
rest = testList[index+1:]