# Create an auto-cucumber program [duplicate]

Oops, Auto-correct.

You have a word. But it's wrong. You wonder what word it would be. Thankfully, being a code golfer, You can make a code to take a rough guess.

# I/O

You will be given a (wrong, all lowercase) word, and a '(All lowercase)Dictionary list'. You have to output the word with the least Levenshtein distance to the wrong word. If there are multiple words of the same levenshtein distance, use the last one in the list.

# Examples

Input => Output
(["apple", "banana", "orange", "pineapple"], "baenanae") => "banana"
(["zeal", "zealot", "zealotry", "zealots", "zealous", "zealously", "zealousness"], "zealousl") => "zealously"
(["abductors", "abducts", "abe", "abeam", "abel"], "") => "abe"


# Python 3 + pylev, 77 bytes

lambda m,s:min({levenshtein(x,s):x for x in m}.items())[1]
from pylev import*


Try it on repl.it!

• Shouldn't that be [-1]? Ah no my bad... what happens with multiple minima? – Jonathan Allan Sep 10 '17 at 5:16
• See my edit above - I assumed you wanted to get the rightmost (as per requirements) but noticed it was getting the second of two values. Try the zealousl example. (possibly for x in m[::-1] will do it) – Jonathan Allan Sep 10 '17 at 5:18
• @JonathanAllan I had missed that part of the spec, but nevertheless the correct answer is always given. If any of the distances are the same, the earlier ones will be overwritten by the later ones, since a dictionary can only have one value for a key. – LyricLy Sep 10 '17 at 5:26
• Oh of course, sweet side-effects Batman :) – Jonathan Allan Sep 10 '17 at 5:27

# 05AB1E, 6 bytes

Σ.L(}¤


Try it online! (note: the trailing newline on the input is necessary for the empty string case.)

### How?

Σ.L(}¤ - implicitly push the first input (the dictionary list)
Σ   }  - sort the list by:
-   implicitly push second input (the misspelled word)
.L    -   Levenshtein distance
(   -   negated
¤ - tail the sorted list  and place the entry on the top of the stack
- implicitly print top of stack