lst2D = [
[1,2,3],
[4,5,6],
[7,8,9],
[3,2,1]
]
from typing import NoReturn
def exploreList(lst:list) -> NoReturn:
for idx in range( len(lst) ):
print(“Index = %d,Value = %r,Type = %r”\
%(idx,lst[idx],type(lst[idx])))
if type(lst[idx]) is list:
exploreList(lst[idx])
exploreList(lst2D)
dic = {
1: {“Depart”: “Physics”, “Professor”: “儲蓄保險王”},
2: {“Depart”: “Math”, “Professor”: “正義真話俠”}
}
dic[3] = {“Depart”: “Chemistry”, “Professor”: “SavingKing”}
print(dic)
print(dic[1][“Professor”])
cable = {
“UFA125A”:{(13.95, 0.4):[2.84988,2.74828,4.8768,0.254]}
同一條cable “UFA125A”
有一樣的K1,K2
但可能會有一樣或不一樣的長度
使用巢狀dict,儲存這樣的資料
.keys() .values() 多了一層[] (長度=1的list)
list[0] 才能取出預期的
key為tuple, values為單層list
list(cable[‘UFA125A’].keys())[0]
list(cable[‘UFA125A’].values())[0]
推薦hahow線上學習python: https://igrape.net/30afN
近期留言