[Tutor] Iterating backwards

James Newton jnewton at fuelindustries.com
Fri Jan 11 18:36:38 CET 2008


Kent Johnson wrote: 
>I guess counters is iterable but not a sequence. Try this:
>   for vCounter in reversed(list(counters)):

Hi Kent,

Thanks for your help.  This solves my problem:

    vPos = pygame.mouse.get_pos()
    for vCounter in reversed(list(counters)):
        if vCounter.rect.collidepoint(*vPos):
            # vCounter now points to the sprite we want to treat
            break

:-)

James


More information about the Tutor mailing list