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