You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 
 

36 lines
805 B

  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)