This line:
return [some_list.append(random.randint(0, b)) for x in xrange(number)]
... is a list comprehension that generates the result of number
calls to some_list.append(...)
, all of which return None
:
>>> print gen(10)
[None, None, None, None, None, None, None, None, None, None]
None
s compare like this:
>>> None < None
False
>>> None > None
False
So I would imagine both of your sorts are rather confused.
The quicksort is faster because with a list of None
s, it becomes a function that copies a list:
def quick_sort_r(some_list):
e = []
if len(some_list) <= 1:
return some_list
else:
pivot = some_list[0]
for x in some_list:
# all other comparisons are False
e.append(x)
return e
In summary, use return [random.randint(0, b) for x in xrange(number)]
instead. On my machine, that change takes the quicksort from 0.43s to 8.9s, which is probably more what you were expecting.
Incidentally, unless you have a fast machine, Python isn't going to agree with a list of 1,000,000 numbers very well - it takes my (somewhat slow) computer about 3 seconds to generate a list of 1 million numbers.