Why does list have no 'get' method?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Feb 7 04:06:52 EST 2008


On Thu, 07 Feb 2008 00:20:52 -0800, bearophileHUGS wrote:

> I think a high-level language like Python must have boolean operators
> (or and not) that behave in a much more clean way, with a simpler
> semantics. That is they have to return only true or false. Otherwise
> they are just a source of bugs and confusion.

Well, that's one opinion.

Boolean operators can be complicated to understand if you write 
complicated expressions, or if you don't understand what they do. But 
otherwise, they're no more complicated than arithmetic expressions.

[...]
> That trick with or/and may look good for Perl, but it's unfit for a
> language that tries to be clear, readable from people that don't know it
> much, and good to learn to program. Python has now the if-then
> expression too that is more clear.

Suppose I have two lists, and want to process the first one if it is not 
empty, otherwise process the second. I'd write it like this:

process(mylist or yourlist)

You're suggesting I should write it like this:

process(mylist if mylist else yourlist)


With the greatest respect, I think that if you think the second example 
"is more clear", you're completely bonkers. *grins*


-- 
Steven



More information about the Python-list mailing list