5. 數(shù)據(jù)結(jié)構(gòu)

5. 數(shù)據(jù)結(jié)構(gòu)

本章將詳細(xì)介紹一些您已經(jīng)了解的內(nèi)容块促,并添加了一些新內(nèi)容荣堰。

5.1. 列表的更多特性

列表數(shù)據(jù)類型還有很多的方法。這里是列表對(duì)象方法的清單:

<dl class="method" style="margin-bottom: 15px;">

<dt>list.``append(x)</dt>

<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; text-align: justify; line-height: 20.8px;">

在列表的末尾添加一個(gè)元素竭翠。相當(dāng)于 a[len(a):] = [x] 振坚。

</dd>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt>list.``extend(iterable)</dt>

<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; text-align: justify; line-height: 20.8px;">

使用可迭代對(duì)象中的所有元素來(lái)擴(kuò)展列表。相當(dāng)于 a[len(a):] = iterable 斋扰。

</dd>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt>list.``insert(i, x)</dt>

<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; text-align: justify; line-height: 20.8px;">

在給定的位置插入一個(gè)元素渡八。第一個(gè)參數(shù)是要插入的元素的索引啃洋,所以 a.insert(0, x) 插入列表頭部, a.insert(len(a), x) 等同于 a.append(x) 屎鳍。

</dd>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt>list.``remove(x)</dt>

<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; text-align: justify; line-height: 20.8px;">

移除列表中第一個(gè)值為 x 的元素宏娄。如果沒(méi)有這樣的元素,則拋出 ValueError 異常逮壁。

</dd>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt>list.``pop([i])</dt>

<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; text-align: justify; line-height: 20.8px;">

刪除列表中給定位置的元素并返回它孵坚。如果沒(méi)有給定位置,a.pop() 將會(huì)刪除并返回列表中的最后一個(gè)元素窥淆。( 方法簽名中 i 兩邊的方括號(hào)表示這個(gè)參數(shù)是可選的卖宠,而不是要你輸入方括號(hào)。你會(huì)在 Python 參考庫(kù)中經(jīng)秤欠梗看到這種表示方法)扛伍。

</dd>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt>list.``clear()</dt>

<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; text-align: justify; line-height: 20.8px;">

刪除列表中所有的元素。相當(dāng)于 del a[:] 词裤。

</dd>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt>list.``index(x[, start[, end]])</dt>

<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; text-align: justify; line-height: 20.8px;">

返回列表中第一個(gè)值為 x 的元素的從零開(kāi)始的索引刺洒。如果沒(méi)有這樣的元素將會(huì)拋出 ValueError 異常。

可選參數(shù) startend 是切片符號(hào)亚斋,用于將搜索限制為列表的特定子序列作媚。返回的索引是相對(duì)于整個(gè)序列的開(kāi)始計(jì)算的,而不是 start 參數(shù)帅刊。

</dd>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt>list.``count(x)</dt>

<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; text-align: justify; line-height: 20.8px;">

返回元素 x 在列表中出現(xiàn)的次數(shù)纸泡。

</dd>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt>list.``sort(key=None, reverse=False)</dt>

<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; text-align: justify; line-height: 20.8px;">

對(duì)列表中的元素進(jìn)行排序(參數(shù)可用于自定義排序,解釋請(qǐng)參見(jiàn) sorted())赖瞒。

</dd>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt>list.``reverse()</dt>

<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; text-align: justify; line-height: 20.8px;">

反轉(zhuǎn)列表中的元素女揭。

</dd>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt>list.``copy()</dt>

<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; text-align: justify; line-height: 20.8px;">

返回列表的一個(gè)淺拷貝。相當(dāng)于 a[:] 栏饮。

</dd>

</dl>

列表方法示例:

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">
fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
fruits.count('apple')
2
fruits.count('tangerine')
0
fruits.index('banana')
3
fruits.index('banana', 4) # Find next banana starting a position 4
6
fruits.reverse()
fruits


</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt>list.``sort(key=None, reverse=False)</dt>

<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; text-align: justify; line-height: 20.8px;">

對(duì)列表中的元素進(jìn)行排序(參數(shù)可用于自定義排序吧兔,解釋請(qǐng)參見(jiàn) sorted())。

</dd>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt>list.``reverse()</dt>

<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; text-align: justify; line-height: 20.8px;">

反轉(zhuǎn)列表中的元素袍嬉。

</dd>

</dl>

<dl class="method" style="margin-bottom: 15px;">

<dt>list.``copy()</dt>

<dd style="margin-top: 3px; margin-bottom: 10px; margin-left: 30px; text-align: justify; line-height: 20.8px;">

返回列表的一個(gè)淺拷貝境蔼。相當(dāng)于 a[:]

</dd>

</dl>

列表方法示例:

>>><pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">
>>> fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
>>> fruits.count('apple')
2
>>> fruits.count('tangerine')
0
>>> fruits.index('banana')
3
>>> fruits.index('banana', 4) # Find next banana starting a position 4
6
>>> fruits.reverse()
>>> fruits
['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange']
fruits.append('grape')
fruits
['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange', 'grape']
fruits.sort()
fruits
['apple', 'apple', 'banana', 'banana', 'grape', 'kiwi', 'orange', 'pear']
fruits.pop()
'pear'
</pre>

你可能已經(jīng)注意到伺通,像 insert 箍土,remove 或者 sort 方法,只修改列表罐监,沒(méi)有打印出返回值——它們返回默認(rèn)值 None 吴藻。[1] 這是Python中所有可變數(shù)據(jù)結(jié)構(gòu)的設(shè)計(jì)原則。

5.1.1. 列表作為棧使用

列表方法使得列表作為堆棧非常容易弓柱,最后一個(gè)插入沟堡,最先取出(“后進(jìn)先出”)侧但。要添加一個(gè)元素到堆棧的頂端,使用 append() 航罗。要從堆棧頂部取出一個(gè)元素禀横,使用 pop() ,不用指定索引伤哺。例如

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;"

stack = [3, 4, 5]
stack.append(6)
stack.append(7)
stack
[3, 4, 5, 6, 7]
stack.pop()

>>> fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
>>> fruits.count('apple')
2
>>> fruits.count('tangerine')
0
>>> fruits.index('banana')
3
>>> fruits.index('banana', 4) # Find next banana starting a position 4
6
>>> fruits.reverse()
>>> fruits
['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange']
>>> fruits.append('grape')
>>> fruits
['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange', 'grape']
>>> fruits.sort()
>>> fruits
['apple', 'apple', 'banana', 'banana', 'grape', 'kiwi', 'orange', 'pear']
>>> fruits.pop()
'pear'
</pre>

你可能已經(jīng)注意到燕侠,像 insertremove 或者 sort 方法立莉,只修改列表绢彤,沒(méi)有打印出返回值——它們返回默認(rèn)值 None[1] 這是Python中所有可變數(shù)據(jù)結(jié)構(gòu)的設(shè)計(jì)原則蜓耻。

### 5.1.1. 列表作為棧使用

列表方法使得列表作為堆棧非常容易茫舶,最后一個(gè)插入,最先取出(“后進(jìn)先出”)刹淌。要添加一個(gè)元素到堆棧的頂端饶氏,使用 append() 。要從堆棧頂部取出一個(gè)元素有勾,使用 pop() 疹启,不用指定索引。例如

>>>

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;"
>>>> stack = [3, 4, 5]
>>> stack.append(6)
>>> stack.append(7)
>>> stack
[3, 4, 5, 6, 7]
>>> stack.pop()
7
stack
[3, 4, 5, 6]
stack.pop()
6
stack.pop()
5
stack
[3, 4]
</pre>

5.1.2. 列表作為隊(duì)列使用

列表也可以用作隊(duì)列蔼卡,其中先添加的元素被最先取出 (“先進(jìn)先出”)喊崖;然而列表用作這個(gè)目的相當(dāng)?shù)托АR驗(yàn)樵诹斜淼哪┪蔡砑雍蛷棾鲈胤浅雇逞?旎缍窃诹斜淼拈_(kāi)頭插入或彈出元素卻很慢 (因?yàn)樗械钠渌囟急仨氁苿?dòng)一位)。

若要實(shí)現(xiàn)一個(gè)隊(duì)列塘砸, collections.deque 被設(shè)計(jì)用于快速地從兩端操作节仿。例如

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> from collections import deque

queue = deque(["Eric", "John", "Michael"])
queue.append("Terry") # Terry arrives
queue.append("Graham") # Graham arrives
queue.popleft() # The first to arrive now leaves
'Eric'
queue.popleft() # The second to arrive now leaves
'John'
queue # Remaining queue in order of arrival
deque(['Michael', 'Terry', 'Graham'])
</pre>

5.1.3. 列表推導(dǎo)式

列表推導(dǎo)式提供了一個(gè)更簡(jiǎn)單的創(chuàng)建列表的方法。常見(jiàn)的用法是把某種操作應(yīng)用于序列或可迭代對(duì)象的每個(gè)元素上掉蔬,然后使用其結(jié)果來(lái)創(chuàng)建列表廊宪,或者通過(guò)滿足某些特定條件元素來(lái)創(chuàng)建子序列。

例如女轿,假設(shè)我們想創(chuàng)建一個(gè)平方列表箭启,像這樣

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;"

squares = []
for x in range(10):
... squares.append(x**2)
...
squares
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
</pre>

注意這里創(chuàng)建(或被重寫)的名為 x 的變量在for循環(huán)后仍然存在。我們可以計(jì)算平方列表的值而不會(huì)產(chǎn)生任何副作用

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">squares = list(map(lambda x: x**2, range(10)))
</pre>

或者谈喳,等價(jià)于

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">squares = [x**2 for x in range(10)]
</pre>

上面這種寫法更加簡(jiǎn)潔易讀。

列表推導(dǎo)式的結(jié)構(gòu)是由一對(duì)方括號(hào)所包含的以下內(nèi)容:一個(gè)表達(dá)式戈泼,后面跟一個(gè) for 子句婿禽,然后是零個(gè)或多個(gè) forif 子句赏僧。 其結(jié)果將是一個(gè)新列表,由對(duì)表達(dá)式依據(jù)后面的 forif 子句的內(nèi)容進(jìn)行求值計(jì)算而得出扭倾。 舉例來(lái)說(shuō)淀零,以下列表推導(dǎo)式會(huì)將兩個(gè)列表中不相等的元素組合起來(lái):

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]
</pre>

而它等價(jià)于

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> combs = []

for x in [1,2,3]:
... for y in [3,1,4]:
... if x != y:
... combs.append((x, y))
...
combs
[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]
</pre>

注意在上面兩個(gè)代碼片段中, forif 的順序是相同的膛壹。

如果表達(dá)式是一個(gè)元組(例如上面的 (x, y))驾中,那么就必須加上括號(hào)

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> vec = [-4, -2, 0, 2, 4]

create a new list with the values doubled

[x*2 for x in vec]
[-8, -4, 0, 4, 8]

filter the list to exclude negative numbers

[x for x in vec if x >= 0]
[0, 2, 4]

apply a function to all the elements

[abs(x) for x in vec]
[4, 2, 0, 2, 4]

call a method on each element

freshfruit = [' banana', ' loganberry ', 'passion fruit ']
[weapon.strip() for weapon in freshfruit]
['banana', 'loganberry', 'passion fruit']

create a list of 2-tuples like (number, square)

[(x, x**2) for x in range(6)]
[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]

the tuple must be parenthesized, otherwise an error is raised

[x, x2 for x in range(6)]
File "<stdin>", line 1, in <module>
[x, x
2 for x in range(6)]
^
SyntaxError: invalid syntax

flatten a list using a listcomp with two 'for'

vec = [[1,2,3], [4,5,6], [7,8,9]]
[num for elem in vec for num in elem]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
</pre>

列表推導(dǎo)式可以使用復(fù)雜的表達(dá)式和嵌套函數(shù)

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> from math import pi

[str(round(pi, i)) for i in range(1, 6)]
['3.1', '3.14', '3.142', '3.1416', '3.14159']
</pre>

5.1.4. 嵌套的列表推導(dǎo)式

列表推導(dǎo)式中的初始表達(dá)式可以是任何表達(dá)式,包括另一個(gè)列表推導(dǎo)式模聋。

考慮下面這個(gè) 3x4的矩陣肩民,它由3個(gè)長(zhǎng)度為4的列表組成

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> matrix = [
... [1, 2, 3, 4],
... [5, 6, 7, 8],
... [9, 10, 11, 12],
... ]
</pre>

下面的列表推導(dǎo)式將交換其行和列

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> [[row[i] for row in matrix] for i in range(4)]
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
</pre>

如上節(jié)所示,嵌套的列表推導(dǎo)式是基于跟隨其后的 for 進(jìn)行求值的链方,所以這個(gè)例子等價(jià)于:

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> transposed = []

for i in range(4):
... transposed.append([row[i] for row in matrix])
...
transposed
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
</pre>

反過(guò)來(lái)說(shuō)持痰,也等價(jià)于

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> transposed = []

for i in range(4):
... # the following 3 lines implement the nested listcomp
... transposed_row = []
... for row in matrix:
... transposed_row.append(row[i])
... transposed.append(transposed_row)
...
transposed
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
</pre>

實(shí)際應(yīng)用中,你應(yīng)該會(huì)更喜歡使用內(nèi)置函數(shù)去組成復(fù)雜的流程語(yǔ)句祟蚀。 zip() 函數(shù)將會(huì)很好地處理這種情況

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> list(zip(*matrix))
[(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
</pre>

關(guān)于本行中星號(hào)的詳細(xì)說(shuō)明工窍,參見(jiàn) 解包參數(shù)列表

5.2. del 語(yǔ)句

有一種方式可以從列表按照給定的索引而不是值來(lái)移除一個(gè)元素: 那就是 del 語(yǔ)句前酿。 它不同于會(huì)返回一個(gè)值的 pop() 方法患雏。 del 語(yǔ)句也可以用來(lái)從列表中移除切片或者清空整個(gè)列表(我們之前用過(guò)的方式是將一個(gè)空列表賦值給指定的切片)。 例如:

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> a = [-1, 1, 66.25, 333, 333, 1234.5]

del a[0]
a
[1, 66.25, 333, 333, 1234.5]
del a[2:4]
a
[1, 66.25, 1234.5]
del a[:]
a
[]
</pre>

del 也可以被用來(lái)刪除整個(gè)變量

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> del a
</pre>

此后再引用 a 時(shí)會(huì)報(bào)錯(cuò)(直到另一個(gè)值被賦給它)罢维。我們會(huì)在后面了解到 del 的其他用法淹仑。

5.3. 元組和序列

我們看到列表和字符串有很多共同特性,例如索引和切片操作言津。他們是 序列 數(shù)據(jù)類型(參見(jiàn) 序列類型 --- list, tuple, range)中的兩種攻人。隨著 Python 語(yǔ)言的發(fā)展,其他的序列類型也會(huì)被加入其中悬槽。這里介紹另一種標(biāo)準(zhǔn)序列類型: 元組怀吻。

一個(gè)元組由幾個(gè)被逗號(hào)隔開(kāi)的值組成,例如

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> t = 12345, 54321, 'hello!'

t[0]
12345
t
(12345, 54321, 'hello!')

Tuples may be nested:

... u = t, (1, 2, 3, 4, 5)

u
((12345, 54321, 'hello!'), (1, 2, 3, 4, 5))

Tuples are immutable:

... t[0] = 88888
Traceback (most recent call last): File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment

but they can contain mutable objects:

... v = ([1, 2, 3], [3, 2, 1])

v
([1, 2, 3], [3, 2, 1])
</pre>

如你所見(jiàn)初婆,元組在輸出時(shí)總是被圓括號(hào)包圍的蓬坡,以便正確表示嵌套元組。輸入時(shí)圓括號(hào)可有可無(wú)磅叛,不過(guò)經(jīng)常會(huì)是必須的(如果這個(gè)元組是一個(gè)更大的表達(dá)式的一部分)屑咳。給元組中的一個(gè)單獨(dú)的元素賦值是不允許的,當(dāng)然你可以創(chuàng)建包含可變對(duì)象的元組弊琴,例如列表兆龙。

雖然元組可能看起來(lái)與列表很像,但它們通常是在不同的場(chǎng)景被使用敲董,并且有著不同的用途紫皇。元組是 immutable(不可變的)慰安,其序列通常包含不同種類的元素,并且通過(guò)解包(這一節(jié)下面會(huì)解釋)或者索引來(lái)訪問(wèn)(如果是 namedtuples 的話甚至還可以通過(guò)屬性訪問(wèn))聪铺。列表是 mutable (可變的)化焕,并且列表中的元素一般是同種類型的,并且通過(guò)迭代訪問(wèn)铃剔。

一個(gè)特殊的問(wèn)題是構(gòu)造包含0個(gè)或1個(gè)元素的元組:為了適應(yīng)這種情況撒桨,語(yǔ)法有一些額外的改變〖担空元組可以直接被一對(duì)空?qǐng)A括號(hào)創(chuàng)建凤类,含有一個(gè)元素的元組可以通過(guò)在這個(gè)元素后添加一個(gè)逗號(hào)來(lái)構(gòu)建(圓括號(hào)里只有一個(gè)值的話不夠明確)。丑陋蝶押,但是有效踱蠢。例如

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> empty = ()

singleton = 'hello', # <-- note trailing comma
len(empty)
0
len(singleton)
1
singleton
('hello',)
</pre>

語(yǔ)句 t = 12345, 54321, 'hello!'元組打包 的一個(gè)例子:值 12345, 54321'hello!' 被打包進(jìn)元組。其逆操作也是允許的

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> x, y, z = t
</pre>

這被稱為 序列解包 也是很恰當(dāng)?shù)钠宓纾驗(yàn)榻獍僮鞯牡忍?hào)右側(cè)可以是任何序列茎截。序列解包要求等號(hào)左側(cè)的變量數(shù)與右側(cè)序列里所含的元素?cái)?shù)相同。注意可變參數(shù)其實(shí)也只是元組打包和序列解包的組合赶盔。

5.4. 集合

Python也包含有 集合 類型企锌。集合是由不重復(fù)元素組成的無(wú)序的集。它的基本用法包括成員檢測(cè)和消除重復(fù)元素于未。集合對(duì)象也支持像 聯(lián)合撕攒,交集,差集烘浦,對(duì)稱差分等數(shù)學(xué)運(yùn)算抖坪。

花括號(hào)或 set() 函數(shù)可以用來(lái)創(chuàng)建集合。注意:要?jiǎng)?chuàng)建一個(gè)空集合你只能用 set() 而不能用 {}闷叉,因?yàn)楹笳呤莿?chuàng)建一個(gè)空字典擦俐,這種數(shù)據(jù)結(jié)構(gòu)我們會(huì)在下一節(jié)進(jìn)行討論。

以下是一些簡(jiǎn)單的示例:

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}

print(basket) # show that duplicates have been removed
{'orange', 'banana', 'pear', 'apple'}
'orange' in basket # fast membership testing
True
'crabgrass' in basket
False

Demonstrate set operations on unique letters from two words

...

a = set('abracadabra')
b = set('alacazam')
a # unique letters in a
{'a', 'r', 'b', 'c', 'd'}
a - b # letters in a but not in b
{'r', 'd', 'b'}
a | b # letters in a or b or both
{'a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'}
a & b # letters in both a and b
{'a', 'c'}
a ^ b # letters in a or b but not both
{'r', 'd', 'b', 'm', 'z', 'l'}
</pre>

類似于 列表推導(dǎo)式握侧,集合也支持推導(dǎo)式形式

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> a = {x for x in 'abracadabra' if x not in 'abc'}

a
{'r', 'd'}
</pre>

5.5. 字典

另一個(gè)非常有用的 Python 內(nèi)置數(shù)據(jù)類型是 字典 (參見(jiàn) 映射類型 --- dict)蚯瞧。字典在其他語(yǔ)言里可能會(huì)被叫做 聯(lián)合內(nèi)存聯(lián)合數(shù)組。與以連續(xù)整數(shù)為索引的序列不同品擎,字典是以 關(guān)鍵字 為索引的埋合,關(guān)鍵字可以是任意不可變類型,通常是字符串或數(shù)字萄传。如果一個(gè)元組只包含字符串甚颂、數(shù)字或元組,那么這個(gè)元組也可以用作關(guān)鍵字。但如果元組直接或間接地包含了可變對(duì)象振诬,那么它就不能用作關(guān)鍵字瓣铣。列表不能用作關(guān)鍵字,因?yàn)榱斜砜梢酝ㄟ^(guò)索引贷揽、切片或 append()extend() 之類的方法來(lái)改變。

理解字典的最好方式梦碗,就是將它看做是一個(gè) 鍵: 值 對(duì)的集合禽绪,鍵必須是唯一的(在一個(gè)字典中)。一對(duì)花括號(hào)可以創(chuàng)建一個(gè)空字典:{} 洪规。另一種初始化字典的方式是在一對(duì)花括號(hào)里放置一些以逗號(hào)分隔的鍵值對(duì)印屁,而這也是字典輸出的方式。

字典主要的操作是使用關(guān)鍵字存儲(chǔ)和解析值斩例。也可以用 del 來(lái)刪除一個(gè)鍵值對(duì)雄人。如果你使用了一個(gè)已經(jīng)存在的關(guān)鍵字來(lái)存儲(chǔ)值,那么之前與這個(gè)關(guān)鍵字關(guān)聯(lián)的值就會(huì)被遺忘念赶。用一個(gè)不存在的鍵來(lái)取值則會(huì)報(bào)錯(cuò)础钠。

對(duì)一個(gè)字典執(zhí)行 list(d) 將返回包含該字典中所有鍵的列表,按插入次序排列 (如需其他排序叉谜,則要使用 sorted(d))旗吁。要檢查字典中是否存在一個(gè)特定鍵,可使用 in 關(guān)鍵字停局。

以下是使用字典的一些簡(jiǎn)單示例

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> tel = {'jack': 4098, 'sape': 4139}

tel['guido'] = 4127
tel
{'jack': 4098, 'sape': 4139, 'guido': 4127}
tel['jack']
4098
del tel['sape']
tel['irv'] = 4127
tel
{'jack': 4098, 'guido': 4127, 'irv': 4127}
list(tel)
['jack', 'guido', 'irv']
sorted(tel)
['guido', 'irv', 'jack']
'guido' in tel
True
'jack' not in tel
False
</pre>

dict() 構(gòu)造函數(shù)可以直接從鍵值對(duì)序列里創(chuàng)建字典很钓。

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])
{'sape': 4139, 'guido': 4127, 'jack': 4098}
</pre>

此外,字典推導(dǎo)式可以從任意的鍵值表達(dá)式中創(chuàng)建字典

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> {x: x**2 for x in (2, 4, 6)}
{2: 4, 4: 16, 6: 36}
</pre>

當(dāng)關(guān)鍵字是簡(jiǎn)單字符串時(shí)董栽,有時(shí)直接通過(guò)關(guān)鍵字參數(shù)來(lái)指定鍵值對(duì)更方便

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> dict(sape=4139, guido=4127, jack=4098)
{'sape': 4139, 'guido': 4127, 'jack': 4098}
</pre>

5.6. 循環(huán)的技巧

當(dāng)在字典中循環(huán)時(shí)码倦,用 items() 方法可將關(guān)鍵字和對(duì)應(yīng)的值同時(shí)取出

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> knights = {'gallahad': 'the pure', 'robin': 'the brave'}

for k, v in knights.items():
... print(k, v)
...
gallahad the pure
robin the brave
</pre>

當(dāng)在序列中循環(huán)時(shí)驼修,用 enumerate() 函數(shù)可以將索引位置和其對(duì)應(yīng)的值同時(shí)取出

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> for i, v in enumerate(['tic', 'tac', 'toe']):
... print(i, v)
...
0 tic
1 tac
2 toe
</pre>

當(dāng)同時(shí)在兩個(gè)或更多序列中循環(huán)時(shí)纪蜒,可以用 zip() 函數(shù)將其內(nèi)元素一一匹配。

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> questions = ['name', 'quest', 'favorite color']

answers = ['lancelot', 'the holy grail', 'blue']
for q, a in zip(questions, answers):
... print('What is your {0}? It is {1}.'.format(q, a))
...
What is your name? It is lancelot.
What is your quest? It is the holy grail.
What is your favorite color? It is blue.
</pre>

當(dāng)逆向循環(huán)一個(gè)序列時(shí)抗碰,先正向定位序列工禾,然后調(diào)用 reversed() 函數(shù)

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> for i in reversed(range(1, 10, 2)):
... print(i)
...
9
7
5
3
1
</pre>

如果要按某個(gè)指定順序循環(huán)一個(gè)序列运提,可以用 sorted() 函數(shù),它可以在不改動(dòng)原序列的基礎(chǔ)上返回一個(gè)新的排好序的序列

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']

for f in sorted(set(basket)):
... print(f)
...
apple
banana
orange
pear
</pre>

有時(shí)可能會(huì)想在循環(huán)時(shí)修改列表內(nèi)容闻葵,一般來(lái)說(shuō)改為創(chuàng)建一個(gè)新列表是比較簡(jiǎn)單且安全的

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> import math

raw_data = [56.2, float('NaN'), 51.7, 55.3, 52.5, float('NaN'), 47.8]
filtered_data = []
for value in raw_data:
... if not math.isnan(value):
... filtered_data.append(value)
...
filtered_data
[56.2, 51.7, 55.3, 52.5, 47.8]
</pre>

5.7. 深入條件控制

whileif 條件句中可以使用任意操作民泵,而不僅僅是比較操作。

比較操作符 innot in 校驗(yàn)一個(gè)值是否在(或不在)一個(gè)序列里槽畔。操作符 isis not 比較兩個(gè)對(duì)象是不是同一個(gè)對(duì)象栈妆,這只跟像列表這樣的可變對(duì)象有關(guān)。所有的比較操作符都有相同的優(yōu)先級(jí),且這個(gè)優(yōu)先級(jí)比數(shù)值運(yùn)算符低鳞尔。

比較操作可以傳遞嬉橙。例如 a < b == c 會(huì)校驗(yàn)是否 a 小于 b 并且 b 等于 c

比較操作可以通過(guò)布爾運(yùn)算符 andor 來(lái)組合寥假,并且比較操作(或其他任何布爾運(yùn)算)的結(jié)果都可以用 not 來(lái)取反市框。這些操作符的優(yōu)先級(jí)低于比較操作符;在它們之中糕韧,not 優(yōu)先級(jí)最高枫振, or 優(yōu)先級(jí)最低,因此 A and not B orC 等價(jià)于 (A and (not B)) or C萤彩。和之前一樣粪滤,你也可以在這種式子里使用圓括號(hào)。

布爾運(yùn)算符 andor 也被成為 短路 運(yùn)算符:它們的參數(shù)從左至右解析雀扶,一旦可以確定結(jié)果解析就會(huì)停止杖小。例如,如果 AC 為真而 B 為假愚墓,那么 A and B and C 不會(huì)解析 C予权。當(dāng)作用于普通值而非布爾值時(shí),短路操作符的返回值通常是最后一個(gè)變量浪册。

也可以把比較操作或者邏輯表達(dá)式的結(jié)果賦值給一個(gè)變量伟件,例如

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">>>> string1, string2, string3 = '', 'Trondheim', 'Hammer Dance'

non_null = string1 or string2 or string3
non_null
'Trondheim'
</pre>

注意 Python 與 C 不同,賦值操作不能發(fā)生在表達(dá)式內(nèi)部议经。C程序員可能會(huì)對(duì)此抱怨斧账,但它避免了一類C程序中常見(jiàn)的錯(cuò)誤:想在表達(dá)式中寫 == 時(shí)卻寫成了 =

5.8. 序列和其它類型的比較

序列對(duì)象可以與相同類型的其他對(duì)象比較煞肾。它們使用 字典順序 進(jìn)行比較:首先比較兩個(gè)序列的第一個(gè)元素咧织,如果不同,那么這就決定了比較操作的結(jié)果籍救。如果它們相同,就再比較每個(gè)序列的第二個(gè)元素蝙昙,以此類推闪萄,直到有一個(gè)序列被耗盡吓妆。如果要比較的兩個(gè)元素本身就是相同類型的序列,那么就遞歸進(jìn)行字典順序比較握巢。如果兩個(gè)序列中所有的元素都相等晕鹊,那么我們認(rèn)為這兩個(gè)序列相等。如果一個(gè)序列是另一個(gè)序列的初始子序列暴浦,那么短序列就小于另一個(gè)溅话。字典順序?qū)ψ址畞?lái)說(shuō),是使用單字符的 Unicode 碼的順序歌焦。下面是同類型序列之間比較的例子

<pre style="overflow: auto hidden; padding: 5px; background-color: rgb(238, 255, 204); color: rgb(51, 51, 51); line-height: 18.528px; border: 1px solid rgb(170, 204, 153); font-family: monospace, sans-serif; font-size: 15.44px; border-radius: 3px;">(1, 2, 3) < (1, 2, 4)
[1, 2, 3] < [1, 2, 4]
'ABC' < 'C' < 'Pascal' < 'Python'
(1, 2, 3, 4) < (1, 2, 4)
(1, 2) < (1, 2, -1)
(1, 2, 3) == (1.0, 2.0, 3.0)
(1, 2, ('aa', 'ab')) < (1, 2, ('abc', 'a'), 4)
</pre>

注意對(duì)不同類型對(duì)象來(lái)說(shuō)飞几,只要待比較對(duì)象提供了合適的比較方法,就可以使用 <> 來(lái)比較独撇。例如屑墨,混合數(shù)值類型是通過(guò)他們的數(shù)值進(jìn)行比較的,所以 0 等于 0.0纷铣,等等卵史。否則,解釋器將拋出一個(gè) TypeError 異常搜立,而不是隨便給出一個(gè)結(jié)果以躯。

腳注

<colgroup><col class="label"><col></colgroup>
| [1] | 別的語(yǔ)言可能會(huì)返回一個(gè)可變對(duì)象,他們?cè)试S方法連續(xù)執(zhí)行啄踊,例如 d->insert("a")->remove("b")->sort();忧设。 |

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市颠通,隨后出現(xiàn)的幾起案子址晕,更是在濱河造成了極大的恐慌,老刑警劉巖顿锰,帶你破解...
    沈念sama閱讀 218,204評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件斩箫,死亡現(xiàn)場(chǎng)離奇詭異吏砂,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)乘客,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,091評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門狐血,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人易核,你說(shuō)我怎么就攤上這事匈织。” “怎么了牡直?”我有些...
    開(kāi)封第一講書人閱讀 164,548評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵缀匕,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我碰逸,道長(zhǎng)乡小,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書人閱讀 58,657評(píng)論 1 293
  • 正文 為了忘掉前任饵史,我火速辦了婚禮满钟,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘胳喷。我一直安慰自己湃番,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,689評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布吭露。 她就那樣靜靜地躺著吠撮,像睡著了一般。 火紅的嫁衣襯著肌膚如雪讲竿。 梳的紋絲不亂的頭發(fā)上泥兰,一...
    開(kāi)封第一講書人閱讀 51,554評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音题禀,去河邊找鬼逾条。 笑死,一個(gè)胖子當(dāng)著我的面吹牛投剥,可吹牛的內(nèi)容都是我干的师脂。 我是一名探鬼主播,決...
    沈念sama閱讀 40,302評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼江锨,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼吃警!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起啄育,我...
    開(kāi)封第一講書人閱讀 39,216評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤酌心,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后挑豌,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體安券,經(jīng)...
    沈念sama閱讀 45,661評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡墩崩,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,851評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了侯勉。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片鹦筹。...
    茶點(diǎn)故事閱讀 39,977評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖址貌,靈堂內(nèi)的尸體忽然破棺而出铐拐,到底是詐尸還是另有隱情,我是刑警寧澤练对,帶...
    沈念sama閱讀 35,697評(píng)論 5 347
  • 正文 年R本政府宣布遍蟋,位于F島的核電站,受9級(jí)特大地震影響螟凭,放射性物質(zhì)發(fā)生泄漏虚青。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,306評(píng)論 3 330
  • 文/蒙蒙 一螺男、第九天 我趴在偏房一處隱蔽的房頂上張望棒厘。 院中可真熱鬧,春花似錦烟号、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 31,898評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至篙耗,卻和暖如春迫筑,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背宗弯。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 33,019評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工脯燃, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人蒙保。 一個(gè)月前我還...
    沈念sama閱讀 48,138評(píng)論 3 370
  • 正文 我出身青樓辕棚,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親邓厕。 傳聞我的和親對(duì)象是個(gè)殘疾皇子逝嚎,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,927評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,332評(píng)論 0 10
  • 數(shù)據(jù)結(jié)構(gòu) '''列表的三個(gè)特性 1、列表的元素可以改變 2详恼、列表的元素是有序的 3补君、列表可以容納任何對(duì)象 ''' ...
    Think4doing閱讀 300評(píng)論 0 0
  • 這段時(shí)間我都在看著一些文章看了很多有關(guān)職業(yè)規(guī)劃的東西挽铁。感觸很多所以在這里想分享一下伟桅。 前幾天看新聞?wù)f一個(gè)海龜...
    思楠生涯規(guī)劃閱讀 254評(píng)論 0 2
  • 小悅和我成為朋友后楣铁,我就經(jīng)常問(wèn)她一些問(wèn)題,這些問(wèn)題有的關(guān)于月經(jīng)够掠,有的關(guān)于作業(yè)民褂,還有的關(guān)于考試。 漸漸熟悉了之后疯潭,我...
    微笑進(jìn)程閱讀 287評(píng)論 0 1
  • 追 文/陶蓉 被夕陽(yáng)映紅的云彩上漂浮著拖著線的風(fēng)箏,壓低的云層似乎隱隱存在著巨大的悲傷赊堪,漸壓漸低,幾乎壓得人透不過(guò)...
    陶蓉子閱讀 426評(píng)論 0 3