misc2.py 808 B

12345678910111213141516171819202122232425262728
  1. # Сортировка строки. В каждом слове содержится число.
  2. # "is2 Thi1s T4est 3a" --> "Thi1s is2 3a T4est"
  3. # "4of Fo1r pe6ople g3ood th5e the2" --> "Fo1r the2 g3ood 4of th5e pe6ople"
  4. #
  5. def order(sentence):
  6. my_list = sentence.split(' ')
  7. new_list = []
  8. print(my_list)
  9. for i in range(len(my_list)):
  10. for j in range(len(my_list)):
  11. if my_list[j].rfind(str(i+1)) != -1:
  12. new_list.append(my_list[j])
  13. return (' '.join(new_list))
  14. #
  15. # def order(sentence):
  16. # return " ".join(sorted(sentence.split(), key=lambda x: int(filter(str.isdigit, x))))
  17. #
  18. # def order(words):
  19. # return ' '.join(sorted(words.split(), key=lambda w:sorted(w)))
  20. print(order("is2 Thi1s T4est 3a"))