list_abecedaire~20171216-160411.py 926 B

123456789101112131415161718192021222324252627
  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. words = set()
  11. # Ask to write a sentence
  12. sentence = "Unless we can begin to embody the notion of change in the words we use, we will continue to be lost"
  13. # print sentence
  14. print("phrase originale:", sentence)
  15. # Split sentence into words
  16. words = sentence.lower().split()
  17. print(words)
  18. # sort words of list
  19. #uniquewords.sort()
  20. #print(uniquewords)
  21. # print sorted wordlist as string
  22. print("phrase alphabétique:", " ".join(words).capitalize(), '.')