list_abecedaire~20171216-155918.py 955 B

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