JSON result parsing

John Gordon gordon at panix.com
Fri Jul 29 23:25:18 EDT 2016


In <fd02ca3a-47af-4a0b-b309-56bc732ea071 at googlegroups.com> TUA <kai.peters at gmail.com> writes:

> I want to retrieve the value for a key 'ID' but only if I have a single result and, obviously, if ID is present.

> How can I do this with pythonic elegance?

> Thanks for all suggestions!

    if len(results) == 1 and 'ID' in results:
        return results['ID']

    else:
        return 'something else'

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list