News for hackers. Stuff that matters.
Re:How to Write a Spelling Corrector by kough on Thursday September 08, 2016 @12:56PM (#12454764)
You can also use the set-comprehension syntax, which functions equivalently but looks slightly nicer:

    return {w for w in words if w in WORDS}
could have also directly used the intersection operator on the sets:

    return words & WORDS
or slightly more verbose, but maybe more clear for colleagues who don't regularly use sets in Python:

    return words.intersection(WORDS)
Re:How to Write a Spelling Corrector by abecedarius on Thursday September 08, 2016 @01:34PM (#12455157)
> return words & WORDS

Not quite. It'd have to be set(WORDS) instead of WORDS -- which'd be expensive. Or WORDS.keys(), which I'm not sure about -- I'd have to benchmark it.

Re:How to Write a Spelling Corrector by desdiv on Thursday September 08, 2016 @02:14PM (#12455574)
You would only need to do set(WORDS) once at the beginning of the program, so its amortized cost is low.
Re:How to Write a Spelling Corrector by xapata on Thursday September 08, 2016 @01:52PM (#12455335)
I wouldn't worry about the expense of set construction vs the expense of an n-squared algorithm.
Re:How to Write a Spelling Corrector by kough on Thursday September 08, 2016 @05:50PM (#12457666)
caught me, I hadn't read through the article, wasn't sure whether or not WORDS was a set or a dict. Like desdiv points out, this isn't a big deal, you can maintain an equivalent WORDS structure that is a set.