mardi 4 septembre 2018

Is it possible to 'not print a dictionary based on the values?

I have a dictionary and would like to know if it's possible to "not print" the dictionary if there is a given value:

This is my dictionary:

    d={'Port':'1/0/1','Link-Status':'Down', 'Vlans':'None'}

I would like to know if there is a way to check the Values in the dictionary, and in this example, if Vlans is 'None', don't print the dictionary.

I tried doing a 'for' condition, but it's not working at all:

for v in d.items():
if v is not 'None':
    print(d)

This is what I'm getting from that output:

{'Port': '1/0/1', 'Link-Status': 'Down', 'Vlans': 'None'}
{'Port': '1/0/1', 'Link-Status': 'Down', 'Vlans': 'None'}
{'Port': '1/0/1', 'Link-Status': 'Down', 'Vlans': 'None'}

Aucun commentaire:

Enregistrer un commentaire