1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to split text without spaces into list of words

Discussão em 'Python' iniciado por Stack, Agosto 19, 2025.

  1. Stack

    Stack Membro Participativo

    Input: "tableapplechairtablecupboard..." many words

    What would be an efficient algorithm to split such text to the list of words and get:

    Output: ["table", "apple", "chair", "table", ["cupboard", ["cup", "board"]], ...]

    First 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)

    P.S.
    We have a list of all possible words.
    Word "cupboard" can be "cup" and "board", select longest.
    Language: python, but main thing is the algorithm itself.

    Continue reading...

Compartilhe esta Página