First way
_1. only key
new_ids = {10722774: 5537170, 10722775: 5537171, 10722776: 5537172, 10722777: 5537173, 10722778: 5537174, 10722779: 5537175, 10722780: 5537176, 10722781: 5537177, 10722782: 5537178}
old_ids = {10722773: 5537179, 10722764: 5537170, 10722765: 5537171, 10722766: 5537172, 10722767: 5537173, 10722768: 5537174, 10722769: 5537175, 10722770: 5537176, 10722771: 5537177, 10722772: 5537178}
notLst = [k for k,v in old_ids.items() if v not in new_ids.values()]
print(notLst)
OUTPUT
[10722773]
_2. both key and value
new_ids = {10722774: 5537170, 10722775: 5537171, 10722776: 5537172, 10722777: 5537173, 10722778: 5537174, 10722779: 5537175, 10722780: 5537176, 10722781: 5537177, 10722782: 5537178}
old_ids = {10722773: 5537179, 10722764: 5537170, 10722765: 5537171, 10722766: 5537172, 10722767: 5537173, 10722768: 5537174, 10722769: 5537175, 10722770: 5537176, 10722771: 5537177, 10722772: 5537178}
notLst = {k:v for k,v in old_ids.items() if v not in new_ids.values()}
print(notLst)
Output
{10722773: 5537179}
There are more ways too. Fastest way also
Second Way
You can use a set way too to solve the problem
new_ids = {10722774: 5537170, 10722775: 5537171, 10722776: 5537172, 10722777: 5537173, 10722778: 5537174, 10722779: 5537175, 10722780: 5537176, 10722781: 5537177, 10722782: 5537178}
old_ids = {10722773: 5537179, 10722764: 5537170, 10722765: 5537171, 10722766: 5537172, 10722767: 5537173, 10722768: 5537174, 10722769: 5537175, 10722770: 5537176, 10722771: 5537177, 10722772: 5537178}
# n = set.symmetric_difference(set(new_ids.values()),set(old_ids.values()))
n = set(new_ids.values()) ^ set(old_ids.values())
notLst = {k:v for k,v in old_ids.items() if v in n} # both key Value
# notLst = [k for k,v in old_ids.items() if v in n] # Only key
print(notLst)
Output
{10722773: 5537179} # for both key value
[10722773] # for only key
Time difference between my second way and the @AKK way
from timeit import timeit
new_ids = {10722774: 5537170, 10722775: 5537171, 10722776: 5537172, 10722777: 5537173, 10722778: 5537174, 10722779: 5537175, 10722780: 5537176, 10722781: 5537177, 10722782: 5537178}
old_ids = {10722773: 5537179, 10722764: 5537170, 10722765: 5537171, 10722766: 5537172, 10722767: 5537173, 10722768: 5537174, 10722769: 5537175, 10722770: 5537176, 10722771: 5537177, 10722772: 5537178}
def myway():
# n = set.symmetric_difference(set(new_ids.values()),set(old_ids.values()))
n = set(new_ids.values()) ^ set(old_ids.values())
notLst = {k:v for k,v in old_ids.items() if v in n} # both key Value
# notLst = [k for k,v in old_ids.items() if v in n] # Only key
return notLst
def AKKway():
flipped_old = {v: k for k, v in old_ids.items()}
flipped_new = {v: k for k, v in new_ids.items()}
flipped_combined = flipped_old | flipped_new
# Find keys that aren't shared between the flipped dicts
uncommon_keys = set(flipped_old) ^ set(flipped_new)
# Generate a dict that unflips the key-values containing only the uncommon keys
uncommon = {flipped_combined[v]: v for v in uncommon_keys}
return (uncommon)
print("My way",timeit(myway,number=10000))
print("Akk way",timeit(AKKway,number=10000))
OUTPUT
My way 0.010995300021022558
Akk way 0.028010500012896955