Movatterモバイル変換


[0]ホーム

URL:


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

Sven R. Kunzesrkunze at mail.de
Tue Feb 28 13:10:15 EST 2017


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 except3. advantage: no weird workaround with slices and additional item accessThanks for bringing this up, Michel. First point would be most important to me.Sven-------------- next part --------------An HTML attachment was scrubbed...URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170228/5f51444b/attachment-0001.html>


More information about the Python-ideasmailing list

[8]ページ先頭

©2009-2026 Movatter.jp