求改正,循環(huán)三層,加上了list中的每個(gè)元素
d = {
? ? 'Alice': [45],
? ? 'Bob': [60],
? ? 'Candy': [75],
}
l = ([50, 61, 66],[80, 61, 66],[88, 75, 90])
n = ['Alice','Bob','Candy']
for x in n:
? ? for y in l:
? ? ? ? for z in y:
? ? ? ? ? ? d[x].append(z)
print(d)
2024-02-17
d = {
? ? 'Alice': [45],
? ? 'Bob': [60],
? ? 'Candy': [75],
}
# 一般來(lái)說(shuō)盡可能的使用標(biāo)準(zhǔn)庫(kù)自帶的函數(shù),少加班哦
d['Alice'].extend([50, 61, 66])
d['Bob'].extend([80, 61, 66])
d['Candy'].extend([88, 75, 90])
print(d)
2023-03-10
2022-06-26
d = {'Alice': [45],'Bob': [60],'Candy': [75]}
l = ([50, 61, 66],[80, 61, 66],[88, 75, 90])
n = ['Alice','Bob','Candy']
num = 0
for x in n:
for z in l[num]:
d[x].append(z)
num += 1
print(d)
2022-05-26
2021-12-10
d = {'Alice': [45],'Bob': [60],'Candy': [75],}
l = ([50, 61, 66],[80, 61, 66],[88, 75, 90])
n = ['Alice','Bob','Candy']
for x in n:
? ? for z in l:
? ? ? ? d[x]=z
print(d)
如果希望的是用新的數(shù)組中的數(shù)據(jù)替換原字典中的值,可以用賦值的方式給字典新的值。
#輸出結(jié)果是:
{'Alice': [88, 75, 90], 'Bob': [88, 75, 90], 'Candy': [88, 75, 90]}