python for with double test

2005-12-30 Thread [EMAIL PROTECTED]
hi all
the is a way for doing  a for with double test:
   example
 for i in range(0,10) and f==1:
  
  

thanx  everyone

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python for with double test

2005-12-30 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
 hi all
 the is a way for doing  a for with double test:
example
  for i in range(0,10) and f==1:
   

Not sure if you're asking a question, but is this what you are trying to 
do? :

if f == 1:
for i in range(0,10):
...

If not, please explain more carefully what you want, maybe with an 
example showing more than ... in the body so we'll understand better.

-Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python for with double test

2005-12-30 Thread Szabolcs Nagy
for i in range(0,10):
if f!=1: break
...

i=0
while i10 and f==1:
...
i+=1

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python for with double test

2005-12-30 Thread Alan Franzoni
Il 30 Dec 2005 09:02:30 -0800, [EMAIL PROTECTED] ha scritto:

 hi all
 the is a way for doing  a for with double test:

what's a 'double test' exactly? :-)

'for' does no test, it just iterates over a list. If you want to execute
the iteration only if f is 1, do this:

if f==1:
for i in range(0,10):
...

if you want to use only certain values in the range, when the value of f[i]
(f may be a list, a dictionary, or whatever) is 1, you can use a list
comprehension:

for i in [x for x in range(0,10) if f[x]==1]:


of course, if you want to make it shorter, you can define a function
instead of the 'for' code block and use the list comprehension directly:

def myfunction(x):
...


[myfunction(x) for x in range(0,10) if f[x]==1]


and you'll end up with a list of the return values of myfunction.

-- 
Alan Franzoni [EMAIL PROTECTED]
-
Togli .xyz dalla mia email per contattarmi.
To contact me, remove .xyz from my email address.
-
GPG Key Fingerprint:
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E
-- 
http://mail.python.org/mailman/listinfo/python-list