Slide 21
Slide 21 text
Rust vs Python/Ruby/PHP - Type System
def quicksort(values):
if not values:
return []
else:
pivot = values[0]
less = [x for x in values if x < pivot]
more = [x for x in values[1:] if x >= pivot]
return quicksort(less) + [pivot] + quicksort(more)
print(quicksort([4, 2, 1, 5])) # [1, 2, 4, 5]
print(quicksort("hello")) # ['e', 'h', 'l', 'l', 'o']
print(quicksort(-1))
Traceback (most recent call last):
File "sort.py", line 12, in
print(quicksort(-1))
File "sort.py", line 5, in quicksort
pivot = values[0]
TypeError: 'int' object is not subscriptable