1.”二维列表”

```def initialize_2d_list(w, h, val=None):
return [[val for x in range(w)] for y in range(h)] ```

```>>> initialize_2d_list(2,2)
[[None, None], [None, None]]

>>> initialize_2d_list(2,2,0)
[[0, 0], [0, 0]]       ```

2.函数切割数组

```def bifurcate_by(lst, fn):
return [
[x for x in lst if fn(x)],
[x for x in lst if not fn(x)]
] ```

```>>> bifurcate_by(['beep', 'boop', 'foo', 'bar'], lambda x: x[0] == 'b')
[['beep', 'boop', 'bar'], ['foo']]       ```

3.”交集点”

```def intersection_by(a, b, fn):
_b = set(map(fn, b))
return [item for item in a if fn(item) in _b] ```

```>>> from math import floor
>>> intersection_by([2.1, 1.2], [2.3, 3.4],floor)
[2.1] ```

4.最大值下标

```def max_element_index(arr):
return arr.index(max(arr)) ```

```>>> max_element_index([5, 8, 9, 7, 10, 3, 0])
4 ```

5.数组对称差

```def symmetric_difference(a, b):
_a, _b = set(a), set(b)
return [item for item in a if item not in _b] + [item for item in b if item not in _a] ```

```>>> symmetric_difference([1, 2, 3], [1, 2, 4])
[3, 4] ```

​Python实用宝典 (pythondict.com)