Hi all, I'm trying to do a sort function and I'm having some trouble. The function is actually not sorting, it is something with passing the arguments that I don't understand. I know that the lists are passed by reference therefore this example should work, but it doesn't.
p/s please don't tell my about build-in function .sort()
how many numbers do you want?: 10
unsorted [365283, 240490, 441964, 411424, 78927, 737039, 305545, 808196, 595894, 857359]
sorted [365283, 240490, 441964, 411424, 78927, 737039, 305545, 808196, 595894, 857359]
p/s please don't tell my about build-in function .sort()
import sys
from random import randint
def switch (a,b):
temp = a
a = b
b = temp
def sortList(data):
for x in range (len(data)):
for y in range (len(data)):
if data[x] > data[y]:
switch(data[x],data[y])
L = []
data = int(input("how many numbers do you want?: "))
for i in range(data):
L.append(randint(1,1000000))
print('unsorted',L)
sortList(L)
print('sorted',L)===================output==================================================how many numbers do you want?: 10
unsorted [365283, 240490, 441964, 411424, 78927, 737039, 305545, 808196, 595894, 857359]
sorted [365283, 240490, 441964, 411424, 78927, 737039, 305545, 808196, 595894, 857359]
