Re: [Tutor] circular looping

2010-05-24 Thread Matthew Wood
This is a GREAT application for generators! def cycle(seq, index): l = len(seq) for i in range(len(seq)): cursor = (i + index) % l yield seq[cursor] Then you just pass it the starting index you want, and all is well in the world. :-) Also, gratuitous use of the enumerate

Re: [Tutor] circular looping

2010-05-24 Thread Alan Gauld
"Bala subramanian" wrote But here the value of y changes sequentially. I want y to cycle through the list something like the following. Is there any function to do such circular iteration. cycle 1 y's value should be 'N', 'L', 'C', 'M, 'R' index 1,2,3,4,0 of myres cycle 2 y's value should

[Tutor] circular looping

2010-05-24 Thread Bala subramanian
Friends, I have a list. I have to do some comparison of each item in the list with each other items in the list. from numpy import zeros a=zeros((5,5)) myres=['R', 'N', 'L', 'C', 'M'] DON=['R','N','L'] ; ALL=['R','L','M','S'] for x in myres: for y in myres: if x in DON: