[Python-ideas] get() method for list and tuples

Chris Barker chris.barker at noaa.gov
Fri Mar 3 16:26:50 EST 2017


On Fri, Mar 3, 2017 at 12:33 PM, Sven R. Kunze <srkunze at mail.de> wrote:

> Right now, I could not think of an example "non-trivial and simple and
> small enough" especially in the context of JSON. But maybe the other
> proponents have.
>

Always a challenge -- sorry to lack imagination, I tend to need concrete
examples to "get" some things.

And so far the concrete examples in this thread seem to have been
unconvincing...

Which doesn't mean at all that there aren't good and common-enough use
cases..

The part of data series from simulations (so proper datastructures
> available). So, data lists which aren't filled yet or have not filled till
> a certain amount yet I need some special pieces from them like the first, a
> sample, the 300th, etc. This was the case recently.
>

I deal with that a fair bit -- but in that case, if I need, say the 300th
sample, and there are not yet 300 available, then that IS an Exception I
want to handle.

if it didn't need to be the 300th, but rather an random sample, or maybe
one "half way through the data", or .... then I would compute that index
from teh length or something...

Though I'm probably misunderstanding this use case.

There was also the case of a refactoring going on in some project, where
> things changed from dicts to lists (upgrade of a third party lib, I think).
> As a consequence, I needed to blow up certain functions from n one-liners
> [a.get] to n four-liners [try/except].
>

well, THAT I would blame on the third party lib..... :-)

-CHB

-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170303/dbfef975/attachment.html>


More information about the Python-ideas mailing list