python中批量访问字典中指定键的值


 

>>> test1 = {"key1":"aa","key2":"bb","key3":"cc","key4":"dd","key5":"ee","key6":"ff","key7":"gg"} >>> type(test1) <class 'dict'>
>>> len(test1) 7
>>> for i in test1: print(i) key1 key2 key3 key4 key5 key6 key7 >>> keys=["key7","key4","key2"] >>> for i in test1: if i in keys: print(i,test1[i]) key2 bb key4 dd key7 gg

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM