Keys in dict and keys not in dict

Ben Finney ben+python at benfinney.id.au
Mon Mar 19 00:18:52 EDT 2018


Chris Angelico <rosuav at gmail.com> 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"}
    missing = expected - set(json.keys())

-- 
 \             “The greater the artist, the greater the doubt; perfect |
  `\       confidence is granted to the less talented as a consolation |
_o__)                                           prize.” —Robert Hughes |
Ben Finney




More information about the Python-list mailing list