On Wed, Mar 1, 2017 at 11:13 AM, Abe Dillon <abedil...@gmail.com> wrote:
> I'd like to +1 this proposal. It should be trivial to implement. It won't > break backward compatibility. It's intuitive. I can think of several places > I would use it. I can't think of a good reason not to include it. > I've yet to see in this thread a use case where list.get() would make sense. Specifically, I've yet to see a case where there is straightforward duck-typing substitutability between dicts and lists where you'd want that. I saw something that said "semi-structured data sources like JSON are often messy and you need lots of try/except blocks." But that's really not the same thing. Even if some node in a structure might variously be a list, dict, or scalar (or other types; sets?), I haven't seen any code where this hypothetical list.get() would improve that problem. In contrast, *iteration* is definitely a case where I often want to freely substitute lists, sets, dicts, and other collections. They share that natural capability, so being able to type `for x in collection:` is a good generic win to have. As I've said, the huge difference is that the "keys" to a list have a clear and obvious relationship amongst themselves. They are always successive non-negative integers, with the minimum always being zero. That makes a whole lot of operations and assumptions very different from dictionaries whose keys are completely independent of each other. If `mylist[N]` works, `mylist[N-1]` cannot fail with an IndexError (obviously unless the list is mutated in between those operations); there's nothing remotely analogous for dictionaries, and that's the reason we have dict.get(). -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/