Saturday, 24 August 2013

py3 issue swaping 2 elements in same list

py3 issue swaping 2 elements in same list

So i know there are predefined functions but im still practicing the basics.
I want to sort a bunch of integers in a list from lowest to bigest number.
I defined this function:
def swap(a, b):
c = a
a = b
b = c
return a, b
And this is what im trying:
def low_to_big_sort():
n = [2, 1, 63, 6, 8, 5, 12]
swap(n[0], n[1])
return n
Returns the same list as defined. What is wrong in my code?

No comments:

Post a Comment