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.
 
 
 
 
 
 

46 lines
1000 B

  1. def clean_fragment(fragment):
  2. result = ""
  3. for c in fragment:
  4. if c.isalpha() or c in ["-", "'"]:
  5. result += c
  6. return result
  7. def split_words(text):
  8. fragments = split_fragments(text)
  9. res = list()
  10. for fragment in fragments:
  11. fragment = fragment.lower()
  12. fragment = clean_fragment(fragment)
  13. if fragment:
  14. res.append(fragment)
  15. return res
  16. def split_fragments(text):
  17. res = list()
  18. for fragment in text.split():
  19. if "’" in fragment:
  20. (before, after) = fragment.split("’")
  21. res.append(before)
  22. res.append(after)
  23. else:
  24. res.append(fragment)
  25. return res
  26. def get_frequencies(words):
  27. res = dict()
  28. for word in words:
  29. if word in res:
  30. res[word] += 1
  31. else:
  32. res[word] = 1
  33. return res
  34. words = ["pomme", "poire", "banane", "poire", "banane", "banane"]
  35. frequencies = get_frequencies(words)
  36. print(frequencies)