Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # At the top of your program, import difflib
- import difflib
- # You'll be using names of businesses
- FRUITS = ['apple', 'banana', 'orange']
- a_fruit = 'appel'
- # get_close_matches wants a single string and a list of strings
- best_matches = difflib.get_close_matches(a_fruit, FRUITS)
- # If there are any matches...
- if best_matches:
- # Then choose the first one in the list.
- actual_fruit = best_matches[0]
- else:
- # Otherwise something went wrong, ask the user again.
- print "That was not a valid fruit."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement