Skip to content

Commit f3c9456

Browse files
committed
第1节完成
1 parent 5e420f6 commit f3c9456

16 files changed

+673
-12
lines changed

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
build/
1+
build/
2+
.idea/
3+
*.pyc

Diff for: .idea/.name

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/encodings.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/inspectionProfiles/Project_Default.xml

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/inspectionProfiles/profiles_settings.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/misc.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/modules.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/python3-cookbook.iml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/scopes/scope_settings.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/vcs.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/workspace.xml

+518
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: cookbook/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
"""
4+
Topic: sample
5+
Desc :
6+
"""
7+

Diff for: cookbook/c01/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
"""
4+
Topic: sample
5+
Desc :
6+
"""
7+

Diff for: source/aboutme.rst

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
* 博客: http://yidao620c.iteye.com/
1010
* GitHub: https://github.com/yidao620c
1111

12+
|
13+
|
14+
|
15+
1216
*主要贡献者*
1317

1418
1. 夏丹 ([email protected])
15-
2. 梁永威 (415320557@qq.com)
16-
3. 莫浩文 (453166604@qq.com)
19+
2. 张三 (zhangsan@gmail.com)
20+
3. lisi (lisi@gmail.com)
1721

1822
|
1923
|

Diff for: source/c01/p01_unpack_sequence_into_separate_variables.rst

+68-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,79 @@
55
----------
66
问题
77
----------
8-
You have an N-element tuple or sequence that you would like to unpack into a collection of N variables.
8+
现在有一个包含N个元素的元祖或者是序列,请问怎样将它里面的值解压后同时赋值给N变量
99

1010
----------
1111
解决方案
1212
----------
13-
Any sequence (or iterable) can be unpacked into variables using a simple assignment operation. The only requirement is that the number of variables and structure match the sequence. For example:
13+
任何的序列(或者是可迭代对象)可以通过一个简单的赋值语句解压并赋值给多个变量。
14+
唯一的前提就是变量的数量必须跟序列元素的数量是一样的。代码示例:
15+
16+
.. code-block:: python
17+
18+
>>> p = (4, 5)
19+
>>> x, y = p
20+
>>> x
21+
4
22+
>>> y
23+
5
24+
>>>
25+
>>> data = [ 'ACME', 50, 91.1, (2012, 12, 21) ]
26+
>>> name, shares, price, date = data
27+
>>> name
28+
'ACME'
29+
>>> date
30+
(2012, 12, 21)
31+
>>> name, shares, price, (year, mon, day) = data
32+
>>> name
33+
'ACME'
34+
>>> year
35+
2012
36+
>>> mon
37+
12
38+
>>> day
39+
21
40+
>>>
41+
42+
如果变量个数和序列元素的个数不匹配,会产生一个异常,代码示例:
43+
44+
.. code-block:: python
45+
46+
>>> p = (4, 5)
47+
>>> x, y, z = p
48+
Traceback (most recent call last):
49+
File "<stdin>", line 1, in <module>
50+
ValueError: need more than 2 values to unpack
51+
>>>
1452
1553
----------
1654
讨论
1755
----------
18-
Unpacking actually works with any object that happens to be iterable, not just tuples or lists. This includes strings, files, iterators, and generators. For example:
56+
实际上,这种解压赋值可以用在任何可迭代对象上面,而不仅仅是列表或者元祖。
57+
包括字符串,文件对象,迭代器和生成器。代码示例:
58+
59+
.. code-block:: python
60+
61+
>>> s = 'Hello'
62+
>>> a, b, c, d, e = s
63+
>>> a
64+
'H'
65+
>>> b
66+
'e'
67+
>>> e
68+
'o'
69+
>>>
70+
71+
有时候,你可能只想解压一部分,丢弃其他的值。对于这种情况Python并没有提供特殊的语法。
72+
但是你可以使用任意变量名去占位,到时候丢掉这些变量就行了。代码示例:
73+
.. code-block::python
74+
75+
>>> data = [ 'ACME', 50, 91.1, (2012, 12, 21) ]
76+
>>> _, shares, price, _ = data
77+
>>> shares
78+
50
79+
>>> price
80+
91.1
81+
>>>
82+
83+
你必须保证你选用的那些占位变量名在其他地方没被使用到。

Diff for: source/chapters/p01_data_structures_algorithms.rst

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
第一章:数据结构和算法
33
=============================
44

5-
Python provides a variety of useful built-in data structures, such as lists, sets, and dictionaries.
6-
For the most part, the use of these structures is straightforward. However,
7-
common questions concerning searching, sorting, ordering, and filtering often arise.
8-
Thus, the goal of this chapter is to discuss common data structures and algorithms
9-
involving data. In addition, treatment is given to the various data structures contained
10-
in the collections module.
5+
Python提供了大量的内置数据结构,包括列表,集合以及字典。大多数情况下使用这些数据结构式很简单的。
6+
但是,我们也会经常碰到到诸如查询,排序和过滤等等这些普遍存在的问题。
7+
因此,这一章的目的就是讨论这些比较常见的问题和算法。
8+
另外,我们也会给出在集合模块collections当中操作这些数据结构的方法。
9+
1110

1211
Contents:
1312

0 commit comments

Comments
 (0)