Beautiful.
Thank you Chris, Ben, Peter and Inada.
On Mar 19, 2018 3:14 AM, "INADA Naoki" wrote:
> > expected = {"foo", "bar", "spam"}
> > missing = expected - set(json.keys())
> >
>
> dict.keys() returns set-like object.
> So `missing = expected - json.keys()` works fine, and it's more e
> expected = {"foo", "bar", "spam"}
> missing = expected - set(json.keys())
>
dict.keys() returns set-like object.
So `missing = expected - json.keys()` works fine, and it's more efficient.
--
INADA Naoki
--
https://mail.python.org/mailman/listinfo/python-list
Ben Finney wrote:
> Chris Angelico writes:
>
>> Sounds like a set operation to me.
>>
>> expected = {"foo", "bar", "spam"}
>> missing = expected - set(json)
>
> That works (because iterating a dict returns its keys). But it is less
> immediately understandable, IMO, than this::
>
> expecte
On Mon, Mar 19, 2018 at 3:18 PM, Ben Finney wrote:
> Chris Angelico writes:
>
>> Sounds like a set operation to me.
>>
>> expected = {"foo", "bar", "spam"}
>> missing = expected - set(json)
>
> That works (because iterating a dict returns its keys). But it is less
> immediately understandable, IM
Chris Angelico writes:
> Sounds like a set operation to me.
>
> expected = {"foo", "bar", "spam"}
> missing = expected - set(json)
That works (because iterating a dict returns its keys). But it is less
immediately understandable, IMO, than this::
expected = {"foo", "bar", "spam"}
missin
On Mon, Mar 19, 2018 at 2:32 PM, Andrew Z 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 av
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