求中位数
|--1.python实现
1 #!/usr/bin/python3
2
3 def calc_num(nums):
4
5 #nums_1 = sorted(nums)
6 if not nums:
7 return None
8
9 nums_1 = sorted(nums)
10
11 le = len(nums_1)
12
13 if le % 2 == 0:
14 return ((nums_1[le // 2 - 1] +nums_1[le // 2]) / 2 )
15
16 else:
17 return (nums_1[le // 2])
18
19
20 nums = [3, 33, 989, 20, 7, 8]
21
22 print(calc_num(nums))
|---测试用例
1 b = [
2 {'id': 101, 'rating': 5.0},
3 {'id': 102, 'rating': 1.0},
4 {'id': 102' 'rating': 2.0},
5 {'id': 102, 'rating': 1.0},
6 ]
思考如何使用快排算法实现