repeated phrases in the text Python

后端 未结 4 653
借酒劲吻你
借酒劲吻你 2021-01-21 02:22

I have a problem and I have no idea how to solve it. Please, give a piece of advice.

I have a text. Big, big text. The task is to find all the repeated phrases which len

4条回答
  •  失恋的感觉
    2021-01-21 02:45

    the crudest way would be to read text in a string. Do a string.split() and get individual words in a list. You could then slice list per three words, and use collections.defaultdict(int) for keeping the count.

    d = collections.defaultdict(int)

    d[phrase]+=1

    as I said, its very crude. But should certainly get you started

提交回复
热议问题