list problem 4 newbie

Duncan Booth duncan.booth at invalid.invalid
Mon Jun 26 03:50:23 EDT 2006


manstey wrote:

> for index in reversed(range(0,len(a)-1)):
>    if '75' in b[index][1]:
>       b[index][1].remove('75')
>       b[index][1].append('99')
> 

What on earth is all that messing around in the for loop intended to do? If 
you want a range from len(a)-2 to 0 inclusive then just do it in range 
directly (and did you really mean not to look at the last element?), if you 
actually just wanted to iterate through b in reverse, then just iterate 
through b in reverse:

b = copy.deepcopy(a)
for element in reversed(b):
   if '75' in element[1]:
      element[1].remove('75')
      element[1].append('99')



More information about the Python-list mailing list