Skip to content

Commit

Permalink
修改标题层级
Browse files Browse the repository at this point in the history
  • Loading branch information
iswbm committed May 23, 2021
1 parent c90a0f7 commit eaf95a8
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 114 deletions.
16 changes: 8 additions & 8 deletions source/c03/c03_01.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 3.1 八种连接列表的方式
![](http://image.iswbm.com/20200804124133.png)

### 1、最直观的相加
## 1、最直观的相加

使用 `+` 对多个列表进行相加,你应该懂,不多说了。

Expand All @@ -17,7 +17,7 @@



### 2、借助 itertools
## 2、借助 itertools

itertools 在 Python 里有一个非常强大的内置模块,它专门用于操作可迭代对象。

Expand All @@ -36,7 +36,7 @@ itertools 在 Python 里有一个非常强大的内置模块,它专门用于
>>>
```

### 3、使用 * 解包
## 3、使用 * 解包

使用 `*` 可以解包列表,解包后再合并。

Expand All @@ -51,7 +51,7 @@ itertools 在 Python 里有一个非常强大的内置模块,它专门用于
>>>
```

### 4、使用 extend
## 4、使用 extend

在字典中,使用 update 可实现原地更新,而在列表中,使用 extend 可实现列表的自我扩展。

Expand All @@ -64,7 +64,7 @@ itertools 在 Python 里有一个非常强大的内置模块,它专门用于
[1, 2, 3, 4, 5, 6]
```

### 5、使用列表推导式
## 5、使用列表推导式

Python 里对于生成列表、集合、字典,有一套非常 Pythonnic 的写法。

Expand All @@ -84,7 +84,7 @@ Python 里对于生成列表、集合、字典,有一套非常 Pythonnic 的



### 6、使用 heapq
## 6、使用 heapq

heapq 是 Python 的一个标准模块,它提供了堆排序算法的实现。

Expand Down Expand Up @@ -124,7 +124,7 @@ sorted(itertools.chain(*iterables))

如果你希望得到一个始终有序的列表,那请第一时间想到 heapq.merge,因为它采用堆排序,效率非常高。但若你不希望得到一个排过序的列表,就不要使用它了。

### 7、借助魔法方法
## 7、借助魔法方法

有一个魔法方法叫 `__add__`,当我们使用第一种方法 list01 + list02 的时候,内部实际上是作用在 `__add__` 这个魔法方法上的。

Expand Down Expand Up @@ -158,7 +158,7 @@ sorted(itertools.chain(*iterables))



### 8. 使用 yield from
## 8. 使用 yield from

在 yield from 后可接一个可迭代对象,用于迭代并返回其中的每一个元素。

Expand Down
16 changes: 8 additions & 8 deletions source/c03/c03_01.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
|image0|

1、最直观的相加
~~~~~~~~~~~~~~~
---------------

使用 ``+`` 对多个列表进行相加,你应该懂,不多说了。

Expand All @@ -19,7 +19,7 @@
>>>
2、借助 itertools
~~~~~~~~~~~~~~~~~
-----------------

itertools 在 Python
里有一个非常强大的内置模块,它专门用于操作可迭代对象。
Expand All @@ -41,7 +41,7 @@ itertools 在 Python
>>>
3、使用 \* 解包
~~~~~~~~~~~~~~~
---------------

使用 ``*`` 可以解包列表,解包后再合并。

Expand All @@ -57,7 +57,7 @@ itertools 在 Python
>>>
4、使用 extend
~~~~~~~~~~~~~~
--------------

在字典中,使用 update 可实现原地更新,而在列表中,使用 extend
可实现列表的自我扩展。
Expand All @@ -72,7 +72,7 @@ itertools 在 Python
[1, 2, 3, 4, 5, 6]
5、使用列表推导式
~~~~~~~~~~~~~~~~~
-----------------

Python 里对于生成列表、集合、字典,有一套非常 Pythonnic 的写法。

Expand All @@ -92,7 +92,7 @@ Python 里对于生成列表、集合、字典,有一套非常 Pythonnic 的
>>>
6、使用 heapq
~~~~~~~~~~~~~
-------------

heapq 是 Python 的一个标准模块,它提供了堆排序算法的实现。

Expand Down Expand Up @@ -135,7 +135,7 @@ heapq 是 Python 的一个标准模块,它提供了堆排序算法的实现。
heapq.merge,因为它采用堆排序,效率非常高。但若你不希望得到一个排过序的列表,就不要使用它了。

7、借助魔法方法
~~~~~~~~~~~~~~~
---------------

有一个魔法方法叫 ``__add__``\ ,当我们使用第一种方法 list01 + list02
的时候,内部实际上是作用在 ``__add__`` 这个魔法方法上的。
Expand Down Expand Up @@ -170,7 +170,7 @@ heapq.merge,因为它采用堆排序,效率非常高。但若你不希望得
>>>
8. 使用 yield from
~~~~~~~~~~~~~~~~~~
------------------

在 yield from 后可接一个可迭代对象,用于迭代并返回其中的每一个元素。

Expand Down
14 changes: 7 additions & 7 deletions source/c03/c03_02.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 3.2 合并字典的 8 种方法
![](http://image.iswbm.com/20200804124133.png)

### 1、最简单的原地更新
## 1、最简单的原地更新

字典对象内置了一个 update 方法,用于把另一个字典更新到自己身上。

Expand Down Expand Up @@ -33,7 +33,7 @@



### 2、先解包再合并字典
## 2、先解包再合并字典

使用 `**` 可以解包字典,解包完后再使用 dict 或者 `{}` 就可以合并。

Expand All @@ -59,7 +59,7 @@



### 3、借助 itertools
## 3、借助 itertools

在 Python 里有一个非常强大的内置模块,它专门用于操作可迭代对象。

Expand All @@ -78,7 +78,7 @@



### 4、借助 ChainMap
## 4、借助 ChainMap

如果可以引入一个辅助包,那我就再提一个, `ChainMap` 也可以达到和 `itertools` 同样的效果。

Expand All @@ -105,7 +105,7 @@



### 5、使用dict.items() 合并
## 5、使用dict.items() 合并

在 Python 3.9 之前,其实就已经有 `|` 操作符了,只不过它通常用于对集合(set)取并集。

Expand Down Expand Up @@ -146,7 +146,7 @@



### 6、最酷炫的字典解析式
## 6、最酷炫的字典解析式

Python 里对于生成列表、集合、字典,有一套非常 Pythonnic 的写法。

Expand All @@ -164,7 +164,7 @@ Python 里对于生成列表、集合、字典,有一套非常 Pythonnic 的



### 7、Python 3.9 新特性
## 7、Python 3.9 新特性

在 2 月份发布的 Python 3.9.04a 版本中,新增了一个抓眼球的新操作符操作符: `|`, PEP584 将它称之为合并操作符(Union Operator),用它可以很直观地合并多个字典。

Expand Down
14 changes: 7 additions & 7 deletions source/c03/c03_02.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
|image0|

1、最简单的原地更新
~~~~~~~~~~~~~~~~~~~
-------------------

字典对象内置了一个 update 方法,用于把另一个字典更新到自己身上。

Expand Down Expand Up @@ -36,7 +36,7 @@
{"name": "xiaoming", "age": 27}
2、先解包再合并字典
~~~~~~~~~~~~~~~~~~~
-------------------

使用 ``**`` 可以解包字典,解包完后再使用 dict 或者 ``{}`` 就可以合并。

Expand All @@ -61,7 +61,7 @@
{'name': 'xiaoming', 'age': 27, 'gender': 'male'}
3、借助 itertools
~~~~~~~~~~~~~~~~~
-----------------

在 Python 里有一个非常强大的内置模块,它专门用于操作可迭代对象。

Expand All @@ -82,7 +82,7 @@ dict 转成字典。
{'name': 'xiaoming', 'age': 27, 'gender': 'male'}
4、借助 ChainMap
~~~~~~~~~~~~~~~~
----------------

如果可以引入一个辅助包,那我就再提一个, ``ChainMap`` 也可以达到和
``itertools`` 同样的效果。
Expand Down Expand Up @@ -111,7 +111,7 @@ itertools 就不会有这个问题)。
{'name': 'xiaoming', 'age': 27}
5、使用dict.items() 合并
~~~~~~~~~~~~~~~~~~~~~~~~
------------------------

在 Python 3.9 之前,其实就已经有 ``|``
操作符了,只不过它通常用于对集合(set)取并集。
Expand Down Expand Up @@ -152,7 +152,7 @@ itertools 就不会有这个问题)。
{'name': 'xiaoming', 'age': 27, 'gender': 'male'}
6、最酷炫的字典解析式
~~~~~~~~~~~~~~~~~~~~~
---------------------

Python 里对于生成列表、集合、字典,有一套非常 Pythonnic 的写法。

Expand All @@ -170,7 +170,7 @@ Python 里对于生成列表、集合、字典,有一套非常 Pythonnic 的
{'name': 'xiaoming', 'age': 27, 'gender': 'male'}
7、Python 3.9 新特性
~~~~~~~~~~~~~~~~~~~~
--------------------

在 2 月份发布的 Python 3.9.04a
版本中,新增了一个抓眼球的新操作符操作符: ``|``\ , PEP584
Expand Down
16 changes: 8 additions & 8 deletions source/c03/c03_03.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 3.3 花式导包的八种方法
![](http://image.iswbm.com/20200804124133.png)

### 1. 直接 import
## 1. 直接 import

人尽皆知的方法,直接导入即可

Expand All @@ -26,7 +26,7 @@ from ... import ... as ...

下面我会一一地给你介绍。

### 2. 使用 \__import__
## 2. 使用 \__import__

`__import__` 函数可用于导入模块,import 语句也会调用函数。其定义为:

Expand Down Expand Up @@ -71,7 +71,7 @@ __import__(name[, globals[, locals[, fromlist[, level]]]])



### 3. 使用 importlib 模块
## 3. 使用 importlib 模块

importlib 是 Python 中的一个标准库,importlib 能提供的功能非常全面。

Expand All @@ -96,7 +96,7 @@ importlib 是 Python 中的一个标准库,importlib 能提供的功能非常



### 4. 使用 imp 模块
## 4. 使用 imp 模块

`imp` 模块提供了一些 import 语句内部实现的接口。例如模块查找(find_module)、模块加载(load_module)等等(模块的导入过程会包含模块查找、加载、缓存等步骤)。可以用该模块来简单实现内建的 `__import__` 函数功能:

Expand All @@ -114,7 +114,7 @@ importlib 是 Python 中的一个标准库,importlib 能提供的功能非常



### 5. 使用 execfile
## 5. 使用 execfile

在 Python 2 中有一个 execfile 函数,利用它可以用来执行一个文件。

Expand All @@ -139,7 +139,7 @@ execfile(filename[, globals[, locals]])



### 6. 使用 exec 执行
## 6. 使用 exec 执行

`execfile` 只能在 Python2 中使用,Python 3.x 里已经删除了这个函数。

Expand All @@ -157,7 +157,7 @@ execfile(filename[, globals[, locals]])



### 7. import_from_github_com
## 7. import_from_github_com

有一个包叫做 **import_from_github_com**,从名字上很容易得知,它是一个可以从 github 下载安装并导入的包。为了使用它,你需要做的就是按照如下命令使用pip 先安装它。

Expand Down Expand Up @@ -195,7 +195,7 @@ sqlalchemy/__init__.py'>,

看了 import_from_github_com的源码后,你会注意到它并没有使用importlib。实际上,它的原理就是使用 pip 来安装那些没有安装的包,然后使用Python的`__import__()`函数来引入新安装的模块。

### 8、远程导入模块
## 8、远程导入模块

我在这篇文章里([深入探讨 Python 的 import 机制:实现远程导入模块](http://mp.weixin.qq.com/s?__biz=MzIzMzMzOTI3Nw==&mid=2247484838&idx=1&sn=1e6fbf5d7546902c6965c60383f7b639&chksm=e8866544dff1ec52e01b6c9a982dfa150b8e34ad472acca35201373dc51dadb5a8630870982a&scene=21#wechat_redirect)),深入剖析了导入模块的内部原理,并在最后手动实现了从远程服务器上读取模块内容,并在本地成功将模块导入的导入器。

Expand Down
Loading

0 comments on commit eaf95a8

Please sign in to comment.