dic = {'a1': 4, 2: '2', '3': [1, 2, 3], 4: {1: 10, 2: 20}}
#dic = dict(a1='4',a2='5')
# 清空字典
dic.clear()
# 取值
print(dic['3'][1])
# 後面的鍵會覆蓋以前的重複鍵
print({'a': 12, 'b': 14, 'a': 18})
# 賦值,若是鍵不存在,就新增這個鍵
dic['bb'] = '666'
# 設置默認值,並返回添加的鍵值
print(dic.setdefault('55', '66'), 'setdefault')
# 將序列內的元素當成key,而後依次把key和value一一對應,返回生成的新字典
print(dic.fromkeys(['a', 'b', 'c', 'd'], [1, 2, 3, 4]), 'fromkeys')
# 獲取鍵值,若是鍵不存在,就返回默認字符
print(dic.get('a2', 'error'), 'get')
# 獲取全部鍵
print(dic.keys(), 'keys')
# 獲取全部鍵值
print(dic.values(), 'values')
# 獲取鍵值對
print(dic.items(), 'items')
# 刪除指定鍵值對,並返回被刪除的鍵值
print(dic.pop('a1'), 'pop')
# 隨機刪除一個鍵值對,並返回被刪除的鍵值對
print(dic.popitem(), 'popitem')
# 更新字典,將其餘字典,合併到當前字典,某些序列update,自己不會更新,會將更新後的內容返回
print(dic.update({'123': 134, '456': 4567}), 'update')
# 將[11, 22, 33, 44, 55, 66, 77, 88, 99, 100]列表裏面小於60的放到字典keya, 大於等於60的放到keyb
templist = [11, 22, 33, 44, 55, 66, 77, 88, 99, 100]
tl1 = []
tl2 = []
for i in templist:
if i >= 60:
tl2.append(i)
else:
tl1.append(i)
dic = {'a': tl1, 'b': tl2}
print(dic)
exit()