string_list_sentencewords~20171216-161706.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python
  2. # encoding=utf8
  3. # Copyright (C) 2016 Constant, Algolit
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details: <http://www.gnu.org/licenses/>.
  12. # Reduction of letters
  13. # From string to list & back
  14. # A string: a list of characters, unchangeable, but treatable
  15. # See: https://www.tutorialspoint.com/python3/python_strings.htm
  16. # Write sentence as string
  17. sentence = "Il fait froid dehors, nous sommes en hiver"
  18. # Print sentence
  19. print("phrase originale:", sentence)
  20. # define new word as list
  21. new_word = []
  22. # Convert sentence in list of words
  23. words = sentence.split(" ")
  24. print(sentence.split(" "))
  25. print(words[1])
  26. print(words[2])
  27. print(words[1])
  28. # For each word in word list
  29. for word in words:
  30. # remove capital letters (string operation)
  31. word = word.lower()
  32. print("phrase en minuscule",)
  33. # Clean punctuation (string operation)
  34. #word = word.strip(" ;''?:,()!.\").”-")
  35. # add word to new word list
  36. #new_word.append(word)
  37. # Write words as one, without punctuation
  38. print("phrase mise en mots:", ''.join(new_word))