Advertisement
acbart

Untitled

Dec 7th, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. # At the top of your program, import difflib
  2. import difflib
  3.  
  4. # You'll be using names of businesses
  5. FRUITS = ['apple', 'banana', 'orange']
  6. a_fruit = 'appel'
  7.  
  8. # get_close_matches wants a single string and a list of strings
  9. best_matches = difflib.get_close_matches(a_fruit, FRUITS)
  10.  
  11. # If there are any matches...
  12. if best_matches:
  13.     # Then choose the first one in the list.
  14.     actual_fruit = best_matches[0]
  15. else:
  16.     # Otherwise something went wrong, ask the user again.
  17.     print "That was not a valid fruit."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement