import random a = random.sample(range(1,100,10) #using the random module sample, random.sample(range, end value, sampling count) smallest = a[0] for i in a: if i < smallest: smallest = i A = smallest
print(a)
print(A)
I want to learn how to sort in descending order without using the list embedding function.
python list sorting
Code using the famous sorting algorithm quicksort.
def sort(array):
less = []
equal = []
greater = []
if len(array) > 1:
pivot = array[0]
for x in array:
if x < pivot:
less.append(x)
if x == pivot:
equal.append(x)
if x > pivot:
greater.append(x)
return sort(less)+equal+sort(greater)
else:
return array
Note: This code is partially modified from a similar question posted in stack overflow.
© 2024 OneMinuteCode. All rights reserved.