phrase_sans_espaces1.py 820 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. # Write sentence as string
  4. sentence = "Je vois La Vie en rose... Tu vois Le Ciel en vert!"
  5. # Print sentence
  6. print("phrase originale:", sentence)
  7. # Convert sentence in one word (remove spaces)
  8. #one_word = sentence.strip(" ")
  9. #print("sans les espaces:", one_word)
  10. # define new word as list
  11. new_word = []
  12. # Convert sentence in list of words
  13. words = sentence.split()
  14. #print(words)
  15. # For each word in word list
  16. for word in words:
  17. # remove capital letters (string operation)
  18. #word = word.lower()
  19. # Clean punctuation (string operation)
  20. #word = word.strip(" ;''?:,()!.\").”-")
  21. # add word to new word list
  22. new_word.append(word)
  23. #new_letter = []
  24. #letter = words.split()
  25. #print(letter)
  26. # Write words as one, without spaces
  27. print("phrase sans espaces:", "".join(new_word))