![]() ![]() The best way to proceed is to model the distribution of the output. (If you want an answer to your original question which does not use word frequency, you need to refine what exactly is meant by "longest word": is it better to have a 20-letter word and ten 3-letter words, or is it better to have five 10-letter words? Once you settle on a precise definition, you just have to change the line defining wordcost to reflect the intended meaning.) Here is a 20-line algorithm that exploits relative word frequency to give accurate results for real-word text. Answer rating: 230Ī naive algorithm won"t give good results when applied to real-world data. Language: python, but main thing is the algorithm itself. Word "cupboard" can be "cup" and "board", select longest. ]įirst thing that cames to mind is to go through all possible words (starting with first letter) and find the longest word possible, continue from position=word_position+len(word) ![]() ![]() What would be an efficient algorithm to split such text to the list of words and get: Input: "tableapplechairtablecupboard." many words ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |