Search code examples
pythonlistdictionary

Filter keys in a list of dictionaries


I'm aiming to print a string, for example 'test', after the 'content' using python, but i have no idea how to do it. I already tried many pages talking about this, but nothing work.

mensagemmm = [

{'isUser': True,},

{'isVerified': None,},

{'isWAContact': True,},

{'profilePicThumbObj': None,},

{'content': 'Test',},

{'quotedMsgId': None,}

]

I already did try most of pages at google, using:

for i in mensagemmm...


Solution

  • Check for content key then print the value

    for i in mensagemmm:
      v = i.get('content')
      if v is not None:
        print(v)
    

    If content key appears more than once in the list of dictionary, each would be printed