"Bala subramanian" <bala.biophys...@gmail.com> 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 be 'L', 'C', 'M, 'R', 'N' index 2,3,4,0,1 ,, cycle 3 y's value should be 'C', 'M', 'R', 'N','L' index 3,4,0,1,2 ,,

The usual trick to get cyclic indices is to use the mod operator
with the length of the list (and maybe adding a constant)

So

L = "RNLCM"
y = 0  -> (y+1) % len(L) -> 1
y = 1                           -> 2
...
y = 4                           -> 0
y = 5                           -> 1
etc....

Does that help?

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to