Advertisement
maxim_shlyahtin

2

Oct 22nd, 2023
960
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. def quickSort(arr):
  2.     if len(arr) <= 1:
  3.         return arr
  4.     pivot = arr[len(arr) // 2]
  5.     left = [word for word in arr if len(word) < len(pivot)]
  6.     middle = [word for word in arr if len(word) == len(pivot)]
  7.     right = [word for word in arr if len(word) > len(pivot)]
  8.     return quickSort(left) + middle + quickSort(right)
  9.  
  10. sentence = input().split()
  11. sorted_sentence = quickSort(sentence)
  12. result = " ".join(sorted_sentence)
  13. print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement