names = ['John', 'Keven'] ages = [10, 12] mydict = dict() for name, age in zip(names, ages): # pay attention here!!! each = dict() print(each) # {} each['name'] = name print(each) # {'name': 'John'} each['age'] = age print(each) # {'name': 'John', 'age': 10} mydict[name] = each print(mydict) # {'John': {'name': 'John', 'age': 10}, 'Keven': {'name': 'Keven', 'age': 12}}
【python】字典添加新值,不替换原来的旧值
于 2022-07-12 12:15:03 首次发布