第十章:數(shù)據(jù)結(jié)構(gòu)

vec = [2, 4, 6]

print([3*x for x in vec])

print(vec)

vec2 = [[x, x+1] for x in vec]

print(vec2)

vec3 = [3*x for x in vec if x>3]

print(vec3)

matrix = [

????[1, 2, 3, 4],

? ? [5, 6, 7, 8],

? ? [9, 10, 11, 12],

]

matrix2 = [[row[i] for row in matrix] for i in range(4)]

print(matrix2)

t =123, 345, 'hello'

print(t[0])

u = t, 1.2, 3.5, 'world'

print(u)

knights = {'gallahad':'the pure', 'robin':'the brave'}

for k, vin knights.items():

? ? ? print(k, v)

questions = ['name', 'quest', 'favorite color']

answers = ['lancelot', 'the holy grail', 'blue']

for q, ain zip(questions, answers):

? ? ? print('What is your {0}? It is {1}.'.format(q, a))

輸出:

[6, 12, 18]

[2, 4, 6]

[[2, 3], [4, 5], [6, 7]]

[12, 18]

[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]

123

((123, 345, 'hello'), 1.2, 3.5, 'world')

gallahad the pure

robin the brave

What is your name? It is lancelot.

What is your quest? It is the holy grail.

What is your favorite color? It is blue.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

  • Lua 5.1 參考手冊 by Roberto Ierusalimschy, Luiz Henrique de F...
    蘇黎九歌閱讀 14,259評論 0 38
  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,671評論 5 6
  • 脂動力酵素21天減脂活動第八天。
    美呀瑩瑩閱讀 190評論 0 0
  • 1.企業(yè)能量模型。企業(yè)生產(chǎn)產(chǎn)品,產(chǎn)品就是勢能,營銷和渠道就是把勢能轉(zhuǎn)化為動能。如果把人比做為企業(yè),那么個人的認知和...
    007胡明閱讀 556評論 0 0
  • 一杯敬朝陽,一杯敬月光,這是我的一天。 一杯敬故鄉(xiāng),一杯敬遠方,這是我的一年。 一杯敬明天,一杯敬過往,這是我的半...
    RebornF閱讀 225評論 1 0

友情鏈接更多精彩內(nèi)容