How To Split A String In Python

Поделиться
HTML-код
  • Опубликовано: 17 ноя 2024
  • НаукаНаука

Комментарии • 6

  • @geryonsosa7766
    @geryonsosa7766 14 дней назад +1

    Thanks man you help me a lot

  • @nguyettoleanh9288
    @nguyettoleanh9288 3 года назад

    Great video! If I have a complex string like below, what should I do to split it into individual words?
    txt = "Thanks for letting me in here. The -- are you guys seeing any strange order patterns as far as like double ordering or any kind of panic inventory rebuild? Anything -- I mean, I would imagine you'd probably see it in transportation and electronics, kind of perhaps equally in transportation and electronics of all the segments. But I'll just leave it at that. Anything on the ordering patterns that's unusual."

    • @CaseDigital
      @CaseDigital  3 года назад +1

      You should just need to do txt.split() or txt.split(“ “) this will give you a list with every word since all your words are separated by spaces. If you want the the punctuation removed you can do something like:
      [curstr.replace(“,”, “”).replace(“.”, “”).replace(“?”,””) for curstr in txt.split(“ “)]
      Or you can use some regex to remove the punctuation as well

    • @nguyettoleanh9288
      @nguyettoleanh9288 3 года назад

      @@CaseDigital great, do you have videos about regex?

    • @CaseDigital
      @CaseDigital  3 года назад +1

      Not at the moment but I’ll put it on my list for videos!

    • @nguyettoleanh9288
      @nguyettoleanh9288 3 года назад

      @@CaseDigital woa. Thank you