Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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,},

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{'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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading