list_abecedaire.py 867 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/python
  2. # this is a shebang: https://en.wikipedia.org/wiki/Shebang_%28Unix%29
  3. '''
  4. This script takes a sentence you write in the terminal, and gives it back in alphabetical order
  5. A list is ordered and changeable. It is less efficient than a set/tuple. But it allows to work with index numbers.
  6. Check out other options for list comprehension: https://docs.python.org/3/tutorial/datastructures.html
  7. Made for OLA #5, Paris, 15-17 décembre 2017
  8. '''
  9. # Ask to write a sentence
  10. sentence = "Les gouvernements suspectent la littérature parce qu’elle est une force qui leur échappe"
  11. # print sentence
  12. print("phrase originale:", sentence)
  13. # Split sentence into words
  14. words = sentence.lower().split()
  15. print(words)
  16. # sort words of list
  17. words.sort()
  18. print(words)
  19. # print sorted wordlist as string
  20. print("phrase alphabétique:", " ".join(words).capitalize()+ '.')