字典的嵌套
字典中嵌套列表与成员的遍历
auto_brand = {
"japan":['toyota','honda','suzuki'],
"germany":['volkswagen','audi','bmw'],
"USA":['ford','cadillac','chevrolet'],
"italy":['maserati','ferrari','lamborghini'],
}
for country_name,brand in auto_brand.items():
print ("\n"+country_name.title()+' have these auto brands:')
for name in brand:
if name == 'bmw':
print (name.upper())
else:
print (name.title())
列表中嵌套字典
all_student_score=[]
for number in range (10):
if number%2==0:
subject_score = {"chinese":90,"math":60,"english":55}
all_student_score.append(subject_score)
else:
subject_score = {"chinese":76,"math":45,"english":33}
all_student_score.insert(number,subject_score)
for motherfucker in all_student_score[:5]:
if motherfucker['chinese'] == 76:
motherfucker['math']= 0
motherfucker['english'] = 0
motherfucker.update(sb='zx')
motherfucker['cnm'] = '2bzx' '''在列表中插入键值'''
motherfucker.update({'zxwcnm':'zxsds','zxcwd':'zxcjj'}) '''另一种插入方法'''
for members in all_student_score:
print (members)