list_abecedaire.py 1003 B

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