summaryrefslogtreecommitdiff
path: root/LectureNotesOnPython.rst
diff options
context:
space:
mode:
authorHui Lan <lanhui@zjnu.edu.cn>2019-07-30 13:33:36 +0800
committerHui Lan <lanhui@zjnu.edu.cn>2019-07-30 13:33:36 +0800
commitdd55397153720cb4db56920768c1bb02ecd85417 (patch)
treebd52b39880eadf5059ebfb71566d71f2c1e7e2fd /LectureNotesOnPython.rst
parent47b714c625fafc02566c3426df82a87c433c4e66 (diff)
LectureNotesOnPython.rst: 添加列表小技巧。 用set(lst)来得到lst中不同的元素。
Diffstat (limited to 'LectureNotesOnPython.rst')
-rw-r--r--LectureNotesOnPython.rst17
1 files changed, 9 insertions, 8 deletions
diff --git a/LectureNotesOnPython.rst b/LectureNotesOnPython.rst
index 322d510..8065a8e 100644
--- a/LectureNotesOnPython.rst
+++ b/LectureNotesOnPython.rst
@@ -1099,14 +1099,15 @@ join方法
别名(Aliasing)
-a = [1, 2, 3]
-b = a
-b is a
-
-把变量名与对象联系起来叫做reference。
-a与b是指向[1,2,3]的两个references。
-因为[1,2,3]是mutable的,所以使用a对[1,2,3]做改变同样影响到b对应的值。
-error-prone(易错)
+ | a = [1, 2, 3]
+ | b = a
+ | b is a
+
+把变量名与对象联系起来叫做reference。 a与b是指向[1,2,3]的两个references。 因为[1,2,3]是mutable的,所以使用a对[1,2,3]做改变同样影响到b对应的值。 error-prone(易错)
+
+
+列表小技巧。 把列表中不同的元素提取出来, 做成另外一个列表。 list(set(lst)) 。
+
**练习** 给定任何一个字符串, 统计其中各个单词出现的频率。 考虑以下几种情况。