freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內容

02-python序列(ppt60頁)-資料下載頁

2025-01-19 23:32本頁面
  

【正文】 []) 由于沒有 ?score?鍵,將增加此鍵,對應值成為空列表 aDict[39。score39。].append(98) aDict[39。score39。].append(97) aDict {39。age39。: 37, 39。score39。: [98, 97], 39。name39。: 39。Dong39。, 39。sex39。: 39。male39。} 52 字典元素的讀取 ? 字典對象的 items()方法 返回字典的 鍵、值元組對列表 ? 字典對象的 keys ()方法 返回字典的 鍵列表 ? 字典對象的 values()方法 返回字典的 值列表 aDict={39。name39。:39。Dong39。, 39。sex39。:39。male39。, 39。age39。:37} for item in (): print(item) (39。age39。, 37) (39。name39。, 39。Dong39。) (39。sex39。, 39。male39。) for key, value in (): print(key, value) age 37 name Dong sex male for key in aDict: print(key) age name sex () dict_keys([39。age39。, 39。name39。, 39。sex39。]) () dict_values([37, 39。Dong39。, 39。male39。]) 53 字典元素的 增 改 刪 ? 當以 指定鍵為下標為字典賦值 時,若鍵存在,則可以修改該鍵的值; 若不存在,則表示添加一個鍵、值對 。 aDict[39。age39。] = 38 aDict {39。age39。: 38, 39。name39。: 39。Dong39。, 39。sex39。: 39。male39。} aDict[39。address39。] = 39。SDIBT39。 aDict {39。age39。: 38, 39。address39。: 39。SDIBT39。, 39。name39。: 39。Dong39。, 39。sex39。: 39。male39。} 54 字典元素的 增 改 刪 ? 使用 字典對象的 update方法 將 另一字典的鍵、值對添加到當前字典對象,如果原字典有相同鍵則修改相應值 aDict={39。age39。: 37, 39。score39。: [98, 97], 39。name39。: 39。Dong39。, 39。sex39。: 39。male39。} () [(39。age39。, 37), (39。score39。, [98, 97]), (39。name39。, 39。Dong39。), (39。sex39。, 39。male39。)] ({39。age39。: 38, 39。a39。:39。a39。,39。b39。:39。b39。}) aDict {39。a39。: 39。a39。, 39。score39。: [98, 97], 39。name39。: 39。Dong39。, 39。age39。: 38, 39。b39。: 39。b39。, 39。sex39。: 39。male39。} 55 字典元素的 增 改 刪 ? 使用 del刪除 字典中 指定鍵的元素 aDict={39。age39。: 37, 39。score39。: [98, 97], 39。name39。: 39。Dong39。, 39。sex39。: 39。male39。} del aDict[39。age39。] aDict {39。sex39。: 39。male39。, 39。name39。: 39。Dong39。, 39。score39。: [98, 97]} ? 使用 字典對象的 clear()方法 來 刪除 字典中 所有元素 () aDict {} ? 使用 字典對象的 pop()方法刪除并返回指定鍵的元素 aDict={39。age39。: 37, 39。score39。: [98, 97], 39。name39。: 39。Dong39。, 39。sex39。: 39。male39。} (39。age39。) 37 aDict {39。sex39。: 39。male39。, 39。name39。: 39。Dong39。, 39。score39。: [98, 97]} ? 使用 字典對象的 popitem方法 隨機 刪除并返回字典中的一個元素 () (39。sex39。, 39。male39。) aDict {39。name39。: 39。Dong39。, 39。score39。: [98, 97]} 56 * 字典應用案例 ? 下面的代碼首先生成包含 1000個隨機字符的字符串,然后統計每個字符的出現次數。 * import string import random x = + + x 39。abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!$%\39。()*+,./:。=?[\\]^_`{|}~39。 y = [(x) for i in range(1000)] () 方法返回列表,元組或字符串中的 隨機項 z = 39。39。.join(y) d = dict() for ch in z: d[ch] = (ch, 0) + 1 57 * 字典應用案例 ? 也可以使用 collections模塊的 defaultdict類來實現該功能。 * import string import random x = + + y = [(x) for i in range(1000)] z = 39。39。.join(y) from collections import defaultdict frequences = defaultdict(int) frequences defaultdict(type 39。int39。, {}) for item in z: frequences[item] += 1 () 58 * 字典應用案例 ? 使用 collections模塊的 Counter類可以快速實現這個功能,并且能夠其他需要,例如查找出現次數最多的元素。下面的代碼演示了 Counter類的用法: * from collections import Counter frequences = Counter(z) () (1) [(39。A39。, 22)] (3) [(39。A39。, 22), (39。39。, 18), (39。`39。, 17)] 59 * 有序字典 ? Python內置字典是無序的。如果需要可以 記住元素插入順序的字典 ,可以使用 。例如下面的代碼: x = dict() 無序字典 x[39。a39。] = 3 x[39。b39。] = 5 x[39。c39。] = 8 x {39。b39。: 5, 39。c39。: 8, 39。a39。: 3} import collections x = () 有序字典 x[39。a39。] = 3 x[39。b39。] = 5 x[39。c39。] = 8 x OrderedDict([(39。a39。, 3), (39。b39。, 5), (39。c39。, 8)]) 60 作 業(yè) 字典 d=,“張三” :76,“李四” :45,“王五” :83,“趙六” :66},寫出下 列操作的代碼: a) 向字典中添加鍵值對“錢七”: 90 b) 修改“李四”的值為 60 c) 刪除“趙六”對應的鍵值對 P80習題 統計整數的個數 P80習題 演講完畢,謝謝觀看!
點擊復制文檔內容
法律信息相關推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1