script1~20171217-163420.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import random
  4. occurences = ["What are the demands","There are no demands","The demands","Impossible demands", "Impossible demand","We demand the impossible","Impossible to demand"]
  5. democracy = "democracy"
  6. democracy_majuscule = democracy.upper()
  7. print(democracy_majuscule)
  8. liste = list( democracy )
  9. random.shuffle( liste )
  10. democracy_shuffled = ''.join( liste )
  11. print(democracy_shuffled)
  12. # read stopwords from file & save them in a list
  13. # read from file
  14. with open("occupy.txt", "r") as source:
  15. # for each line
  16. txt = source.readline()
  17. print(txt)
  18. new_txt = txt.replace(democracy, democracy_shuffled)
  19. print(new_txt)
  20. # clean returns
  21. #line = line.strip()
  22. #print(line)
  23. #replace what are the demands
  24. sentence = occurences[0]
  25. print("sentence:", sentence)
  26. sentence.replace("What are the demands"," what are the demands ")
  27. print(sentence)
  28. #replace there are no demands
  29. sentence = occurences[1]
  30. sentence.replace("there are no demands","therearenodemands")
  31. print(sentence)
  32. #reverse order
  33. sentence = occurences[4,5,7]
  34. chaine = "impossible demands, impossible demand, impossible to demand"
  35. chaine = chaine [::-1]
  36. print(chaine)
  37. # passer en majuscule
  38. sentence = occurences[6]
  39. #sentence = sentence.upper()
  40. #print(sentence)
  41. # écrire la nouvelle liste comme chaîne de caractères dans un fichier texte
  42. #with open('export.txt', 'w') as f:
  43. #f.write(script1)