From the course: Python: Recursion

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Coding the quicksort algorithm in Python

Coding the quicksort algorithm in Python - Python Tutorial

From the course: Python: Recursion

Start my 1-month free trial

Coding the quicksort algorithm in Python

- [Instructor] Okay, so we're now going to code up quicksort in python. So if you're following along with git, then check out Branch 05_02b that's the beginning of this branch. And otherwise just open up quicksort.py anyway in your course exercise files. So let's make a start and we're going to do the base case. If the len of arr now arr is what's being passed in, it's actually technically a list of an array, but informally we can often use those interchangeably how I do sometimes. So if the length for the array is less than or equal to one, then I return the array. Now there's two cases actually here. If it's less than one that means it's zero, which means it's an empty list that's going to be returned. And if the length is one that means there's one item in the list and that will also be returned. So this base case actually covers two different cases as explained in the previous video. So if we're not in the base case…

Contents