Created
June 30, 2022 16:59
-
-
Save hclivess/23dac9126310d5904e3360137c8fd9e6 to your computer and use it in GitHub Desktop.
check if a specific dictionary entry is within a list of dictionaries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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