Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #112039
| From | John Gordon <gordon@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: JSON result parsing |
| Date | 2016-07-30 03:25 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <nnh6mu$k0i$1@reader2.panix.com> (permalink) |
| References | <fd02ca3a-47af-4a0b-b309-56bc732ea071@googlegroups.com> |
In <fd02ca3a-47af-4a0b-b309-56bc732ea071@googlegroups.com> TUA <kai.peters@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@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
JSON result parsing TUA <kai.peters@gmail.com> - 2016-07-29 16:45 -0700 Re: JSON result parsing John Gordon <gordon@panix.com> - 2016-07-30 03:25 +0000 Re: JSON result parsing Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-07-30 17:20 +0100
csiph-web