在python中访问字典列表中的元素

ali*_*ish 2 python dictionary list

大家好,我有字典列表,所有字典都是这样的:

 dict1 = {Label:----,Chapter:----,Section:----,Massage:----}
 dict2 = {Label:----,Chapter:----,Section:----,Massage:----}
 dict3 = {Label:----,Chapter:----,Section:----,Massage:----}
 List = [dict1 , dict2 , dict3]
Run Code Online (Sandbox Code Playgroud)

如果我的标签与字典中的标签相等,我首先想要列表的所有字典打印该字典的消息。

我使用这种方法,但它什么也没得到。

def printMassage(List , mylabel):
    for dicts in List:
        if (Label.value == mylabel):
            print( Massage.value)
Run Code Online (Sandbox Code Playgroud)

请帮我!!

fra*_*ang 5

python中的字典是如何工作的

value = dictionary[key]  # get the `value` of `key` in `dictionary`.
dictionary[key] = newvalue  # change the content of `key` in `dictionary` to `newvalue`.
Run Code Online (Sandbox Code Playgroud)

你的榜样

def printMassage(List , mylabel):
    for dict in List:
        if (dict["Label"] == mylabel):
            print(dict["Massage"])
Run Code Online (Sandbox Code Playgroud)