473,498 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

python for with double test

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

Dec 30 '05 #1
3 1313
for i in range(0,10):
if f!=1: break
...

i=0
while i<10 and f==1:
...
i+=1

Dec 30 '05 #2
bo**********@yahoo.it 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

Dec 30 '05 #3
Il 30 Dec 2005 09:02:30 -0800, bo**********@yahoo.it 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 <al***************@gmail.com>
-
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
Dec 30 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3765
by: Ernie | last post by:
Hi, I am learning swig to use C codes from Python. Here is the swig file mvf.i: %module mvf %include "carrays.i" %array_class(double, doubleArray); %typemap(out) double, float "$result =...
0
2260
by: Natsu Mizutani | last post by:
Hello, I'm trying to wrap a c++ library using MPI inside with boost.python (or SWIG). I managed to find that calling `MPI::Init()` embeded in a c++ funtion would not work. So, I decided to use...
3
6060
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/thinking-outside-the-box-with-python/ . Introduction: I...
16
2568
by: per9000 | last post by:
Hi, I recently started working a lot more in python than I have done in the past. And I discovered something that totally removed the pretty pink clouds of beautifulness that had surrounded my...
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7197
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.