Python implementation of word-wrap alogrithm using dynamic programming (Knuth algorithm)