list_abecedaire~20171216-153953.py 898 B

1234567891011121314151617181920212223242526
  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. # sort words of list
  18. words.sort()
  19. print(words)
  20. # print sorted wordlist as string
  21. print("phrase alphabétique:", " ".join(words).capitalize(), '.')