您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。

1234567891011121314151617181920212223242526272829303132333435
  1. def split_fragments(text):
  2. res = list()
  3. for fragment in contents.split():
  4. if "’" in fragment:
  5. (before, after) = fragment.split("’")
  6. res.append(before)
  7. res.append(after)
  8. else:
  9. res.append(fragment)
  10. return res
  11. def clean_fragment(fragment):
  12. result = ""
  13. for c in fragment:
  14. if c.isalpha() or c in ["-", "'"]:
  15. result += c
  16. return result
  17. def split_words(text):
  18. fragments = split_fragments(text)
  19. res = list()
  20. for fragment in fragments:
  21. fragment = fragment.lower()
  22. fragment = clean_fragment(fragment)
  23. if fragment:
  24. res.append(fragment)
  25. return res
  26. contents = "L’univers est, peut-être, « infini! »"
  27. words = split_words(contents)
  28. print(words)