Re: [Tutor] for loop issue

2009-10-12 Thread Stefan Lesicnik
> Thanks for the tip on enumerate, escaped me. Much like Kent's simply > using a temporary var escaped me despite having done similar things > often... never reply on a tiring Friday. On the bright side this > blunder with indexes, iterators, and lengths has made me more aware of > other contexts f

Re: [Tutor] for loop issue

2009-10-10 Thread Oxymoron
On Sun, Oct 11, 2009 at 4:07 AM, Rich Lovely wrote: > for i, v in enumerate(x[:-1]):  #omitting last value in list to avoid > IndexError >   print v, x[i+1] Thanks for the tip on enumerate, escaped me. Much like Kent's simply using a temporary var escaped me despite having done similar things of

Re: [Tutor] for loop issue

2009-10-10 Thread Rich Lovely
2009/10/9 Oxymoron : > On Fri, Oct 9, 2009 at 11:02 PM, Kent Johnson wrote: >> On Fri, Oct 9, 2009 at 3:54 AM, Stefan Lesicnik wrote: >> >> You can easily keep track of the previous item by assigning it to a >> variable. For example this shows just the increasing elements of a >> sequence: >> >>

Re: [Tutor] for loop issue

2009-10-09 Thread Oxymoron
On Fri, Oct 9, 2009 at 11:02 PM, Kent Johnson wrote: > On Fri, Oct 9, 2009 at 3:54 AM, Stefan Lesicnik wrote: > > You can easily keep track of the previous item by assigning it to a > variable. For example this shows just the increasing elements of a > sequence: > > In [22]: items = [0, 1, 3, 2,

Re: [Tutor] for loop issue

2009-10-09 Thread Kent Johnson
On Fri, Oct 9, 2009 at 3:54 AM, Stefan Lesicnik wrote: > Hi, > > This feels like a strange issue, so i hope I formulate this so its > understandable. > > I have some objects. Each object has associated values. I am looping > through these objects, working with a value and printing out the > value.

Re: [Tutor] for loop issue

2009-10-09 Thread Oxymoron
On Fri, Oct 9, 2009 at 9:35 PM, Oxymoron wrote: > Thus, you can muck around with x[i] (current item), and x[i+1] (next > item), and decide how you want to proceed with the loop. Note the use > of len(x) - 1 rather than just len(x) to easily prevent an IndexError > or extra special case logic. "ea

Re: [Tutor] for loop issue

2009-10-09 Thread Oxymoron
Hello, On Fri, Oct 9, 2009 at 6:54 PM, Stefan Lesicnik wrote: > The issue in this case is that i need to check if the one value > superseeds the other, and in that case, not print it out. I think the > problem is that when you are in the loop, you dont know about the > other object that you haven

[Tutor] for loop issue

2009-10-09 Thread Adam Bark
2009/10/9 Stefan Lesicnik Hi, > > This feels like a strange issue, so i hope I formulate this so its > understandable. > > I have some objects. Each object has associated values. I am looping > through these objects, working with a value and printing out the > value. > The issue in this case is t

[Tutor] for loop issue

2009-10-09 Thread Stefan Lesicnik
Hi, This feels like a strange issue, so i hope I formulate this so its understandable. I have some objects. Each object has associated values. I am looping through these objects, working with a value and printing out the value. The issue in this case is that i need to check if the one value super