[Tutor] sorting / outputting varibales
ted b
phpmoonlighter at yahoo.com
Thu Nov 1 22:13:56 CET 2007
Thanks Kent, and Evert, and everyone,
I really appreciate the advice on etiqutte and all
your help. I will think through my questions much more
thoroughly before any further inquiries and will
'reply to all' as advised.
--- Kent Johnson <kent37 at tds.net> wrote:
> ted b wrote:
>
> > Here's the code i am using, but its a lot of if /
> > thens and i'm trying to find a better way:
> >
> > if var1.value > var2.value > var3.value:
> > objSprites = pygame.sprite.OrderedUpdates
> > (var1, var2, var3)
>
> Did you see Evert's reply to your original question?
> It was pretty close
> to the mark. Though you had not said anything about
> the .value
> attributes until now.
>
> Try this:
> from operator import attrgetter
> vars = [ var1, var2, var3 ]
> vars.sort(key=attrgetter('value'))
> objSprites = pygame.sprite.OrderedUpdates(*vars)
>
> This will sort the vars list by the value attribute
> of each list item,
> then pass the list as the parameter list to
> OrderedUpdates().
>
> Kent
>
> PS Please use Reply All to reply to the list.
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Tutor
mailing list