大家好,我有这样的字典列表:
dict1 = {Label:----,Chapter:----,Section:----,Massage:----}
dict2 = {Label:----,Chapter:----,Section:----,Massage:----}
dict3 = {Label:----,Chapter:----,Section:----,Massage:----}
List = [dict1 , dict2 , dict3]
如果我的标签与字典中的标签相同,我首先要列表中的所有字典打印该字典的消息。
我用了这个方法,但是什么也没得到。
def printMassage(List , mylabel):
for dicts in List:
if (Label.value == mylabel):
print( Massage.value)
请帮帮我!!
请您参考如下方法:
python 中的字典是如何工作的
value = dictionary[key] # get the `value` of `key` in `dictionary`.
dictionary[key] = newvalue # change the content of `key` in `dictionary` to `newvalue`.
你的例子
def printMassage(List , mylabel):
for dict in List:
if (dict["Label"] == mylabel):
print(dict["Massage"])
