Skip to content

Commit fa087b0

Browse files
committed
全局格式修正。
1 parent 0bb36ff commit fa087b0

File tree

254 files changed

+0
-980
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

254 files changed

+0
-980
lines changed

source/c01/p01_unpack_sequence_into_separate_variables.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
现在有一个包含N个元素的元组或者是序列,怎样将它里面的值解压后同时赋值给N个变量?
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -56,8 +54,6 @@
5654
ValueError: need more than 2 values to unpack
5755
>>>
5856
59-
|
60-
6157
----------
6258
讨论
6359
----------

source/c01/p02_unpack_elements_from_iterables.rst

-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
如果一个可迭代对象的元素个数超过变量个数时,会抛出一个 ``ValueError`` 。
99
那么怎样才能从这个可迭代对象中解压出N个元素出来?
1010

11-
|
12-
1311
----------
1412
解决方案
1513
----------
@@ -59,8 +57,6 @@ Python的星号表达式可以用来解决这个问题。比如,你在学习
5957
>>> current
6058
3
6159
62-
|
63-
6460
----------
6561
讨论
6662
----------

source/c01/p03_keep_last_n_items.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
在迭代操作或者其他操作的时候,怎样只保留最后有限几个元素的历史记录?
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -36,8 +34,6 @@
3634
print(line, end='')
3735
print('-' * 20)
3836
39-
|
40-
4137
----------
4238
讨论
4339
----------

source/c01/p04_find_largest_or_smallest_n_items.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
怎样从一个集合中获得最大或者最小的N个元素列表?
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -38,8 +36,6 @@ heapq模块有两个函数:``nlargest()`` 和 ``nsmallest()`` 可以完美解
3836
3937
译者注:上面代码在对每个元素进行对比的时候,会以 ``price`` 的值进行比较。
4038

41-
|
42-
4339
----------
4440
讨论
4541
----------

source/c01/p05_implement_a_priority_queue.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
怎样实现一个按优先级排序的队列? 并且在这个队列上面每次pop操作总是返回优先级最高的那个元素
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -59,8 +57,6 @@
5957
仔细观察可以发现,第一个 ``pop()`` 操作返回优先级最高的元素。
6058
另外注意到如果两个有着相同优先级的元素( ``foo`` 和 ``grok`` ),pop操作按照它们被插入到队列的顺序返回的。
6159

62-
|
63-
6460
----------
6561
讨论
6662
----------

source/c01/p06_map_keys_to_multiple_values_in_dict.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
怎样实现一个键对应多个值的字典(也叫 ``multidict`` )?
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -58,8 +56,6 @@
5856
5957
但是很多程序员觉得 ``setdefault()`` 用起来有点别扭。因为每次调用都得创建一个新的初始值的实例(例子程序中的空列表[])。
6058

61-
|
62-
6359
----------
6460
讨论
6561
----------

source/c01/p07_keep_dict_in_order.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
你想创建一个字典,并且在迭代或序列化这个字典的时候能够控制元素的顺序。
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -38,8 +36,6 @@
3836
'{"foo": 1, "bar": 2, "spam": 3, "grok": 4}'
3937
>>>
4038
41-
|
42-
4339
----------
4440
讨论
4541
----------

source/c01/p08_calculating_with_dict.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
怎样在数据字典中执行一些计算操作(比如求最小值、最大值、排序等等)?
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -52,8 +50,6 @@
5250
print(min(prices_and_names)) # OK
5351
print(max(prices_and_names)) # ValueError: max() arg is an empty sequence
5452
55-
|
56-
5753
----------
5854
讨论
5955
----------

source/c01/p09_find_commonalities_in_dicts.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
怎样在两个字典中寻寻找相同点(比如相同的键、相同的值等等)?
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -49,8 +47,6 @@
4947
c = {key:a[key] for key in a.keys() - {'z', 'w'}}
5048
# c is {'x': 1, 'y': 2}
5149
52-
|
53-
5450
----------
5551
讨论
5652
----------

source/c01/p10_remove_duplicates_from_seq_order.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
怎样在一个序列上面保持元素顺序的同时消除重复的值?
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -56,8 +54,6 @@
5654
5755
如果你想基于单个字段、属性或者某个更大的数据结构来消除重复元素,第二种方案同样可以胜任。
5856

59-
|
60-
6157
----------
6258
讨论
6359
----------

source/c01/p11_naming_slice.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
你的程序已经出现一大堆已无法直视的硬编码切片下标,然后你想清理下代码。
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -30,8 +28,6 @@
3028
3129
第二种版本中,你避免了大量无法理解的硬编码下标,使得你的代码更加清晰可读了。
3230

33-
|
34-
3531
----------
3632
讨论
3733
----------

source/c01/p12_determine_most_freqently_items_in_seq.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
怎样找出一个序列中出现次数最多的元素呢?
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -32,8 +30,6 @@
3230
print(top_three)
3331
# Outputs [('eyes', 8), ('the', 5), ('look', 4)]
3432
35-
|
36-
3733
----------
3834
讨论
3935
----------

source/c01/p13_sort_list_of_dicts_by_key.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
你有一个字典列表,你想根据某个或某几个字典字段来排序这个列表。
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -63,8 +61,6 @@
6361
{'fname': 'Big', 'uid': 1004, 'lname': 'Jones'},
6462
{'fname': 'Brian', 'uid': 1003, 'lname': 'Jones'}]
6563
66-
|
67-
6864
----------
6965
讨论
7066
----------

source/c01/p14_sort_objects_without_compare_support.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
你想排序类型相同的对象,但是他们不支持原生的比较操作。
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -41,8 +39,6 @@
4139
[User(3), User(23), User(99)]
4240
>>>
4341
44-
|
45-
4642
----------
4743
讨论
4844
----------

source/c01/p15_group_records_based_on_field.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
你有一个字典或者实例的序列,然后你想根据某个特定的字段比如 ``date`` 来分组迭代访问。
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -61,8 +59,6 @@
6159
{'date': '07/04/2012', 'address': '5148 N CLARK'}
6260
{'date': '07/04/2012', 'address': '1039 W GRANVILLE'}
6361
64-
|
65-
6662
----------
6763
讨论
6864
----------

source/c01/p16_filter_sequence_elements.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
你有一个数据序列,想利用一些规则从中提取出需要的值或者是缩短序列
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -58,8 +56,6 @@
5856
# Outputs ['1', '2', '-3', '4', '5']
5957
``filter()`` 函数创建了一个迭代器,因此如果你想得到一个列表的话,就得像示例那样使用 ``list()`` 去转换。
6058

61-
|
62-
6359
----------
6460
讨论
6561
----------

source/c01/p17_extract_subset_of_dict.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
你想构造一个字典,它是另外一个字典的子集。
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -29,8 +27,6 @@
2927
tech_names = {'AAPL', 'IBM', 'HPQ', 'MSFT'}
3028
p2 = {key: value for key, value in prices.items() if key in tech_names}
3129
32-
|
33-
3430
----------
3531
讨论
3632
----------

source/c01/p18_map_names_to_sequence_elements.rst

-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
你有一段通过下标访问列表或者元组中元素的代码,但是这样有时候会使得你的代码难以阅读,
99
于是你想通过名称来访问元素。
1010

11-
|
12-
1311
----------
1412
解决方案
1513
----------
@@ -74,8 +72,6 @@
7472
total += s.shares * s.price
7573
return total
7674
77-
|
78-
7975
----------
8076
讨论
8177
----------

source/c01/p19_transform_and_reduce_data_same_time.rst

-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
你需要在数据序列上执行聚集函数(比如 ``sum()`` , ``min()`` , ``max()`` ),
99
但是首先你需要先转换或者过滤数据
1010

11-
|
12-
1311
----------
1412
解决方案
1513
----------
@@ -44,8 +42,6 @@
4442
]
4543
min_shares = min(s['shares'] for s in portfolio)
4644
47-
|
48-
4945
----------
5046
讨论
5147
----------

source/c01/p20_combine_multiple_map_to_single_map.rst

-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
现在有多个字典或者映射,你想将它们从逻辑上合并为一个单一的映射后执行某些操作,
99
比如查找值或者检查某些键是否存在。
1010

11-
|
12-
1311
----------
1412
解决方案
1513
----------
@@ -31,8 +29,6 @@
3129
print(c['y']) # Outputs 2 (from b)
3230
print(c['z']) # Outputs 3 (from a)
3331
34-
|
35-
3632
----------
3733
讨论
3834
----------

source/c02/p01_split_string_on_multiple_delimiters.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
你需要将一个字符串分割为多个字段,但是分隔符(还有周围的空格)并不是固定的。
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -23,8 +21,6 @@
2321
>>> re.split(r'[;,\s]\s*', line)
2422
['asdf', 'fjdk', 'afed', 'fjek', 'asdf', 'foo']
2523
26-
|
27-
2824
----------
2925
讨论
3026
----------

source/c02/p02_match_text_at_start_end.rst

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
----------
88
你需要通过指定的文本模式去检查字符串的开头或者结尾,比如文件名后缀,URL Scheme等等。
99

10-
|
11-
1210
----------
1311
解决方案
1412
----------
@@ -70,8 +68,6 @@
7068
True
7169
>>>
7270
73-
|
74-
7571
----------
7672
讨论
7773
----------

0 commit comments

Comments
 (0)