I am confused about a simple task
the user will give me a string and my program will check if this string equals the first letters of a list of words ( like this example)
>>> html_attr = ["onerror","onload"]
>>> example_task(html_attr,"on")
["onerror","onload"]
>>> example_task(html_attr,"one")
["onerror"]
should I use fuzzywuzzy here or what ?
thanks
CodePudding user response:
No need for some weird libraries, Python has a nice builtin str function called startswith
that does just that.
def example_task(words, beginning):
return [w for w in words if w.startswith(beginning)]
Fuzzywuzzy would come in handy if you don't want an exact match.