TUA <kai.pet...@gmail.com> writes: > Calls to my REST api may either return a dict (for single results) or > a list of dicts (for multiple results).
I think John's answer missed this part. > I receive these results using the requests library. > > I want to retrieve the value for a key 'ID' but only if I have a > single result and, obviously, if ID is present. If r is the result of the request, just testing if 'ID' in r: ... whatever ... would do. The result will be False if r is a list or the single result does not have an ID. > How can I do this with pythonic elegance? Ah, that I leave to others. -- Ben. -- https://mail.python.org/mailman/listinfo/python-list