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