expressed without any state variables or loopsbut wholly through recursiondef quicksort(lst)"quicksort over list-like sequenceif len(lst= return lst pivot lst[ pivots [ for in lst if =pivotsmall quicksort([ for in lst if pivot]large quicksort([ for in lst if pivot]return small pivots large some names are used in the function body to hold convenient valuesbut they are never mutated it would not be as readablebut the definition could be written as single expression if we wanted to do so in factit is somewhat difficultand certainly less intuitiveto transform this into stateful iterative version as general adviceit is good practice to look for possibilities of recursive expression--and especially for versions that avoid the need for state variables or mutable data collections--whenever problem looks partitionable into smaller problems it is not good idea in python--most of the time--to use recursion merely for "iteration by other means eliminating loops just for funlet us take quick look at how we could take out all loops from any python program most of the time this is bad ideaboth for readability and performancebut it is worth looking at how simple it is to do in systematic fashion as background to contemplate those cases where it is actually good idea if we simply call function inside for loopthe built-in higherorder function map(comes to our aidfor in itfunc(estatement-based loop the following code is entirely equivalent to the functional versionexcept there is no repeated rebinding of the variable involvedand hence no statemap(funcitmap()-based "loopeliminating loops