nltk / nltk_book

NLTK Book
http://www.nltk.org/book
403 stars 143 forks source link

Update exercise to avoid `cmp` function #263

Closed lucafrance closed 1 year ago

lucafrance commented 1 year ago

The cmp function has been removed in Python 3.

I believe the original intention of the exercise is to learn sorting with non-alphabetic orders. The exercise is rephrased to achieve the same result without cmp. A solution would be words.sort(key=len), where words is a list of strings.

The issue has been mentioned here: https://github.com/nltk/nltk_book/pull/261#issuecomment-1412303946

stevenbird commented 1 year ago

Thanks. Glad to have a replacement question so that external references to the exercises are preserved.