Why does list have no 'get' method?

2008-02-06 Thread Denis Bilenko
Why does list have no 'get' method with exactly the same semantics as dict's get, that is "return an element if there is one, but do NOT raise an exception if there is not.": def get(self, item, default = None): try: return self[item] except IndexError:

Re: Why does list have no 'get' method?

2008-02-07 Thread Denis Bilenko
Tim Golden wrote: > Dodging your question slightly (and at the risk of teaching > my grandmother to suck eggs) I sometimes use this idiom for > checking params. Obviously it only goes so far, but it's > fairly compact: > > import os, sys > if __name__ == '__main__': > ARGS = None, "DEV" > f

Re: Why does list have no 'get' method?

2008-02-07 Thread Denis Bilenko
Steve Holden wrote: > These versions differ with respect to treatment of blank lines, which > indicates how easy it is to go astray in this kind of semantic > optimization. Your example simply wouldn't work (though you could patch > it up using "if line is None". (despite the use of short-circuiti