本文介绍了如果我在字典中有字典,我怎么称之为for语句,与dictioanrys中的列表相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在字典中有一个字典,在该字典中有一个列表,我如何调用该列表中的项目,字典中的那些,字典中的那些。
I have a dictionary in a dictionary, and a list in that dictionary, how would I call an item from that list, thats in the dictionary, thats in the dictionary.
for dict in Accounts:
for list in dict:
if a in list:
我的尝试:
我曾尝试过上面的代码,但是,令人震惊的是,它没有用,我怎么能这样做?
What I have tried:
I have tried to do the code above, but, un-shockingly, it didn't work, how might I do this?
推荐答案
dictionary = {1:["object1","object2"],2:["object3","object4"]}
你可以做这样的事情来获得清单
you can do something like this to get the list
dictionary = {1:["object1","object2"],2:["object3","object4"]}
#STEP1: Getting the keys
# The below will print the keys in dictionary
for i in dictionary:
print(i)
# STEP 2: Get the specific key
for i in dictionary:
if i==2:
print("Key has been got successfully")
# STEP 3: Copy the value to a seperate list
for i in dictionary:
if i==2:
print("Final List :",dictionary[i])
输出:
OUTPUT:
1
2
Key has been got successfully
Final List : ['object3', 'object4']
这篇关于如果我在字典中有字典,我怎么称之为for语句,与dictioanrys中的列表相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!