On Mon, Mar 19, 2018 at 2:32 PM, Andrew Z <form...@gmail.com> wrote: > hello, > > i'd like to check if a function parameter (json) has all the keys I expect > it to have and if it doesn't - point out the one that is missing. > > What's the good way of doing that? > > "good way" - something concise... i'd like to avoid using : > if key in json: > #pass > else > print(" Oops, i did it again ...")
Sounds like a set operation to me. expected = {"foo", "bar", "spam"} missing = expected - set(json) if missing: print("Missing keys:", missing) ChrisA -- https://mail.python.org/mailman/listinfo/python-list