Re: [Tutor] nested loops

2011-02-07 Thread Alan Gauld
"Steven D'Aprano" wrote I don't think you want to break out of *any* of the loops. Otherwise you will skip testing combinations. In that case I misread the OP. I thought he specifically wanted to avoid testing all the options and exit when he reached his target. In your example, the first t

Re: [Tutor] nested loops

2011-02-07 Thread Steven D'Aprano
Alan Gauld wrote: "Wayne Werner" wrote You probably want to add a sentinel to break out of the outer loops too: I don't think you want to break out of *any* of the loops. Otherwise you will skip testing combinations. In your example, the first time you set highscore and alignment, you break

Re: [Tutor] nested loops

2011-02-07 Thread Michael M Mason
Alan Gauld wrote:- > "Wayne Werner" wrote > found = False > > highscore = 0 > > alignment = somealignment > > for x in something and not found: > > for y in somethingelse and not found: > > for z in evenmoresomething: > > if x+y+z > highscore: > > hi

Re: [Tutor] nested loops

2011-02-07 Thread Alan Gauld
"Wayne Werner" wrote You probably want to add a sentinel to break out of the outer loops too: found = False highscore = 0 alignment = somealignment for x in something and not found: for y in somethingelse and not found: for z in evenmoresomething: if x+y+z > hig

Re: [Tutor] nested loops

2011-02-07 Thread Robert Berman
On 02/07/2011 10:33 AM, Ashley F wrote: I am trying to write a function...(it's kind of like a long way to do BLAST but only comparing 2 sequences) I have 3 loops nested...Within those loops, I obtain a "best fit score" so to speak. I can get the program to run...but the loops run all the way to

Re: [Tutor] nested loops

2011-02-07 Thread Wayne Werner
On Mon, 7 Feb 2011, Ashley F wrote:   To try to clear this up... The part of my pseudocode that I'm having trouble putting into actual code in python is: "if that alignment has the best score seen so far save the score and that alignment" Tip: It's helpful to send code, like perhaps the

Re: [Tutor] nested loops

2005-08-22 Thread Danny Yoo
On Mon, 22 Aug 2005, Kent Johnson wrote: > > Is there any way more efficient for run a nested loop? > > > > -- > > for a in list_a: > > for b in list_b: > > if a == b: break Hi Jonas, Depends on what we're trying to do. Is it necessary to have a nested loop here? What kind of

Re: [Tutor] nested loops

2005-08-22 Thread Alan G
> Is there any way more efficient for run a nested loop? > > -- > for a in list_a: if a in list_b: break Should help a bit, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] nested loops

2005-08-22 Thread Kent Johnson
Jonas Melian wrote: > Is there any way more efficient for run a nested loop? > > -- > for a in list_a: > for b in list_b: > if a == b: break efficient in running time? lines of code? What you have is pretty simple, what don't you like about it? In Python 2.4 you could use a gene