| 123456789101112131415161718192021222324252627 | #!/usr/bin/python# -*- coding: utf-8 -*-# this is a shebang: https://en.wikipedia.org/wiki/Shebang_%28Unix%29'''This script takes a sentence you write in the terminal, and gives it back in alphabetical orderA list is ordered and changeable. It is less efficient than a set/tuple. But it allows to work with index numbers.Check out other options for list comprehension: https://docs.python.org/3/tutorial/datastructures.htmlMade for OLA #5, Paris, 15-17 décembre 2017'''words = set()# Ask to write a sentencesentence = "Unless we can begin to embody the notion of change in the words we use, we will continue to be lost"# print sentenceprint("phrase originale:", sentence)# Split sentence into wordswords = sentence.lower().split()print(words)# sort words of list#uniquewords.sort()#print(uniquewords)# print sorted wordlist as stringprint("phrase alphabétique:", " ".join(words).capitalize(), '.')
 |