Conditional iteration

Carl Banks pavlovevidence at gmail.com
Wed Dec 13 21:10:30 EST 2006


at wrote:
> Well, all I can say that for me as a user it would make sense...

Which is, like, step one out of a hundred for getting a syntax change
into the language.

> Curiosity: in what sense is it redundant?

It creates syntactical support for two different ways to do something.
If your plan were adopted, then we'd have two different spellings for
the same thing:

for i in a:
    if i != 0:
        use(i)

for i in a if i != 0:
    use(i)

Now, redundant syntax isn't a deal breaker by itself.  You have to ask
what is buys you.  In this case, all it does is save you a single level
of indentation--that's it.  There's no performance benefit.  It doesn't
simplify logic.  It doesn't make the code any more readable of clear.
It's only a minor improvement in conciseness.  It hardly saves any
typing (unless you indent by hand).  Even its one clear benefit, saving
indentation, is something you can already get with "if not x:
continue".

Considering how little this syntax change buys, it really doesn't make
a lot of sense for a language that places high emphasis on avoiding
redundancy.


> All solution/workarounds I have seen so far involve creation of new lists
> (subsets) adding to more processing/computation/memory usage. Redundant
> suggests that you know alternatives that don't do that.
>
> Does Guido ever change his mind?

Yes, but I guarantee "it makes sense for me" isn't going to convince
him.  By the way, I'd suggest when posting to comp.lang.python and/or
python-list in the future, you put your replies beneath the quoted text
for the benefit of any future readers (not to mention present readers).


Carl Banks




More information about the Python-list mailing list