I was wondering what the advantages of using the following code to compute the median of a list are
def median_fun(arg):
srtd_list = sorted(arg)
mid = len(arg)/2
if len(arg) % 2 == 0:
return (srtd_list[mid-1] + srtd_list[mid]) / 2.0
else:
return srtd_list[mid]
As opposed to using the following function?
lambda l:l.sort()or(l[len(l)/2]+l[~len(l)/2])/2.
It's my understanding that a lamda function can be used just once in a program. What are some other reasons one would use the first function as opposed to the second function?