I have a string like:
" This is such an nice artwork"
and I have a tag_list ["art","paint"]
Basically, I want to write a function which accepts this string and taglist as inputs
and returns me the word “artwork” as artwork contains the word art which is in taglist.
How do i do this most efficiently?
I want this to be efficient in terms of speed
def prefix_match(string, taglist):
# do something here
return word_in string
Try the following:
This works because
str.startswith()can accept a tuple of prefixes as an argument.Note that I renamed
stringtosentenceso there isn’t any ambiguity with the string module.