Looping over lists

prad prad at towardsfreedom.com
Fri May 4 22:46:15 EDT 2007


On Friday 04 May 2007 18:40:53 Tommy Grav wrote:
> Can anyone help me with the right approach for this
> in python?

for each in a:
    for item in a[a.index(each)+1:]:
        print each,item

will produce 

1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

a.index(each) gives the index of the each value in the a list.
then you just add 1 to it so you start at the index value beside each's index.


-- 
In friendship,
prad

                                      ... with you on your journey
Towards Freedom
http://www.towardsfreedom.com (website)
Information, Inspiration, Imagination - truly a site for soaring I's



More information about the Python-list mailing list