Advertisement
kananmahammadli

Quick_sort list comprehension

May 27th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. from random import*
  2. def qsort(ls):
  3.     if len(ls)<=1:
  4.         return ls
  5.     pivot = choice(ls)
  6.     left=[i for i in ls if i < pivot]
  7.     x =[i for i in ls if i == pivot]
  8.     right =[ i for i in ls if i >pivot]
  9.     return qsort(left) + x + qsort(right)
  10. ls=[randint(0,100) for _ in range(10)]
  11. print(*ls)
  12. print(*qsort(ls))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement