Grr Grr - 2 months ago 3
Python Question

modifying argument value within function

I am trying to figure out a way to modify the order of a list of tuples within a function without returning the list.

For example:

L = [(2,4),(8,5),(1,3),(9,4)]
def sort_ratios(L):
L = sorted(L, key=lambda x: float(x[0])/float(x[1]))
return L

Thus, calling sort_ratios() outputs:


would still be

Instead, I would like to simply modify the value of L without returning anything so that
operates as follows:


It seems trivial, but I just can't seem to get the function to operate this way.


Try L.sort(key=lambda x: float(x[0])/float(x[1])) for an in-place sort.