nltk / nltk_book

NLTK Book
http://www.nltk.org/book
405 stars 142 forks source link

Chapter 3 - Section 9 - Text Wrapping incorrect format #241

Open BetoBob opened 3 years ago

BetoBob commented 3 years ago

Current:

from textwrap import fill
>>> pieces = ["{} {}".format(word, len(word)) for word in saying]
>>> output = ' '.join(pieces)
>>> wrapped = fill(output)
>>> print(wrapped)
After (5), all (3), is (2), said (4), and (3), done (4), , (1), more
(4), is (2), said (4), than (4), done (4), . (1),

Output:

After 5 all 3 is 2 said 4 and 3 done 4 , 1 more 4 is 2 said 4 than 4
done 4 . 1

Fixed:

...
>>> pieces = ["{} ({}),".format(word, len(word)) for word in saying]
...

Output:

After (5), all (3), is (2), said (4), and (3), done (4), , (1), more
(4), is (2), said (4), than (4), done (4), . (1),