目录

* 字典生成式(掌握) <https://www.cnblogs.com/nickchen121/p/10778757.html#字典生成式掌握>
* zip()方法(掌握) <https://www.cnblogs.com/nickchen121/p/10778757.html#zip方法掌握>
字典生成式(掌握)
print({i: i**2 for i in range(10)}) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:
36, 7: 49, 8: 64, 9: 81}
zip()方法(掌握)
keys = ['name', 'age', 'gender'] values = ['nick', 19, 'male'] res = zip(keys,
values) print(F"zip(keys,values): {zip(keys,values)}") info_dict = {k: v for k,
v in res} print(f"info_dict: {info_dict}") zip(keys,values): <zip object at
0x11074c088> info_dict: {'name': 'nick', 'age': 19, 'sex': 'male'}
通过解压缩函数生成一个字典
info_dict = {'name': 'nick', 'age': 19, 'gender': 'male'}
print(f"info_dict.keys(): {info_dict.keys()}") print(f"info_dict.values():
{info_dict.values()}") res = zip(info_dict.keys(), info_dict.values())
print(F"zip(keys,values): {zip(info_dict.keys(),info_dict.values())}")
info_dict = {k: v for k, v in res} print(f"info_dict: {info_dict}")
info_dict.keys(): dict_keys(['name', 'age', 'gender']) info_dict.values():
dict_values(['nick', 19, 'male']) zip(keys,values): <zip object at 0x1105cefc8>
info_dict: {'name': 'nick', 'age': 19, 'gender': 'male'}

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信