On 28.02.2017 18:18, David Mertz wrote:

Yes, and easily written as above. What significant advantage would it have to spell the above as:

    x = alist.get(pos, default_val)

It's a couple characters shorter in the proposed version. I guess I'll concede that needing the odd indexing at the end to get the scalar is slightly ugly.

1. advantage: it looks like dict access -> allows duck typing (oh how often I'd missed that)
2. advantage: no try except
3. advantage: no weird workaround with slices and additional item access


Thanks for bringing this up, Michel. First point would be most important to me.


Sven
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to