Skip to content

Instantly share code, notes, and snippets.

@hclivess
Created June 30, 2022 16:59
Show Gist options
  • Save hclivess/23dac9126310d5904e3360137c8fd9e6 to your computer and use it in GitHub Desktop.
Save hclivess/23dac9126310d5904e3360137c8fd9e6 to your computer and use it in GitHub Desktop.
check if a specific dictionary entry is within a list of dictionaries
target_list = [{"ip": 1, "ad": 0}, {"ip": 2, "ad": 0}]
s2 = {"ip": 2}
s3 = {"ip": 3}
if s2["ip"] not in [x["ip"] for x in target_list]:
print(f"{s2['ip']} is new")
if s3["ip"] not in [x["ip"] for x in target_list]:
print(f"{s2['ip']} is new")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment