On Fri, Mar 3, 2017 at 11:01 AM, Sven R. Kunze <srku...@mail.de> wrote:
> I wonder if those arguing against it also think dicts should not have item > access: > > a[0] > > dict or list? Why should it matter? > Because a mapping that happens to have an integer key is a fundamentally different thing than a sequence. It seems to me that in some of the examples given, the use case really calls for a mapping-with-integers-as-keys, rather than a sequence -- in which case, you could use that, and have the get() :-) And then you could iterate through it the same way, too! you could get closer to sequence behvior by used a OrderedDict -- or maybe even write a SortedDict that would keep the keys in order regardless of when they were added. > a.get(0, 'oops') > Doesn't look so different to me. > but you are going to have issue with other things anyway, notable: for thing in a: # is thing a key or a value????? - Which of the existing things (slice + [default], conditional on a slice, > conditional on a len() call) do you think is the obvious way to do it? > > I think conditional on a len() call is the way to go -- it captures the concept well -- sequences have a certain number of items -- how many this one has is the question at hand. mapping, however, also have a certain number of items, but the number does not indicate which ones are "missing". I guess that's the key point for me -- in all teh examples I seen posed (like parsing args) the sequence may contain from n to n+m items, but a get() doesn' really solve your problem, because the default is probably different depending on how MANY of the possible items are "missing". So get(0 is only helpful if: 1) there is only one possible missing item 2) all the missing items have the same default -- unless that default is sometign like None, in which case you are simply replacing one way to express missing with another, I can't see that being common. So I would expect to see a Sequence /get(0 be used to slightly clean up the code that adds a bunch of Nones to sequences to make them all the same length -- which is actually pretty easy to do anyway: seq = seq + [None] * full_len - len(seq) -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.bar...@noaa.gov
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/