List loops

Bill Hamilton billwerk at gmail.com
Wed Oct 10 01:27:01 CEST 2007


On 10/9/07, John Machin <sjmachin at lexicon.net> wrote:
> On 10/10/2007 1:33 AM, Hamilton, William wrote:
> >> From: Tommy Grav
> >>
> >> Hi everyone,
> >>
> >>    I have a list of objects where I have want to do two loops.
> >> I want to loop over the list and inside this loop, work on all
> >> the elements of the list after the one being handled in the outer
>
> The man said "after" ...
>
> >
> >>>> alist = range(3)
> >>>> for index, i in enumerate(alist):
> >       for jndex, j in enumerate(alist[index:]):
>
> ... so you need index+1 ...
>
> >               print index, jndex, i, j
> >
> >
> > 0 0 0 0
>
> ... to avoid the above unwanted output.
>

Hey, if I got it right, he'd have no work to do himself.  :)


--
-Bill Hamilton



More information about the Python-list mailing list