List loops

John Machin sjmachin at lexicon.net
Tue Oct 9 17:58:48 EDT 2007


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.




More information about the Python-list mailing list