ternary operator

Wojtek Walczak gminick at hacker.pl
Fri Feb 7 17:47:09 CET 2003


Dnia Fri, 7 Feb 2003 16:19:41 GMT, Andrew Koenig napisał(a):
> David> I think that's POOR programming practice!
> 
> Then how would you write the following loop?
> 
>         i = 0;
>         while i < len(n) and x[i] != y:
>                 i += 1
Here's what I'm assuming:

n = "QQQ"
y = "y"
x = "abcdfghy"

and here's the rest of the script:

# here's your way
i = 0
while i < len(n) and x[i] != y:
   i += 1
print i

# the other way ;)
print len(filter(lambda z: z!=y, list(x)[:len(n)]))

...but, well, in almost any case I'd use while loop, and what's _POOR_
for me is top-posting on Usenet rather than using i=0;while ...:... :)

-- 
[ ] gminick (at) underground.org.pl  http://gminick.linuxsecurity.pl/ [ ]
[ "Po prostu lubie poranna samotnosc, bo wtedy kawa smakuje najlepiej." ]




More information about the Python-list mailing list