Re: Finding attributes in a list

2005-04-02 Thread Marcus Goldfish
class Player(object): def __init__(self, **kw): self.__dict__.update(kw) def __repr__(self): return 'Player %s'%getattr(self, 'name', '(anonymous)') import operator [p.name for p in sorted(players, key=operator.attrgetter('attacking'), reverse=True)] Just happened to read this

Re: Finding attributes in a list

2005-04-02 Thread James Stroud
On Saturday 02 April 2005 08:44 pm, Marcus Goldfish wrote: (2) The Player class looks like a nice model for a data table when one wants to sort by arbitrary column. Would you agree? The Player class is (and any class) is absolutely fabulous when you have heterogenous data (string,

Re: Finding attributes in a list

2005-04-02 Thread James Stroud
On Saturday 02 April 2005 09:51 pm, James Stroud wrote: where team could be initialized by a tuple:   class Team(list):     def __init__(self, azip):       for azip in alist:         self.data.append(Player(atup)) Sorry, this should read: where team could be initialized by a list of

Re: Finding attributes in a list

2005-04-02 Thread Bengt Richter
On Sat, 2 Apr 2005 23:44:11 -0500, Marcus Goldfish [EMAIL PROTECTED] wrote: class Player(object): def __init__(self, **kw): self.__dict__.update(kw) def __repr__(self): return 'Player %s'%getattr(self, 'name', '(anonymous)') import operator [p.name for p in sorted(players,

Finding attributes in a list

2005-03-29 Thread Ben
Hi In a list I have a number of soccer players. Each player has a different rating for attacking, defending, midfield fitness and goalkeeping. I have devised a while loop that goes through this list to find the best player at defending, attacking, midfield and goalkeeping. However there is more

Re: Finding attributes in a list

2005-03-29 Thread infidel
You can use the new 'sorted' built-in function and custom compare functions to return lists of players sorted according to any criteria: players = [ ... {'name' : 'joe', 'defense' : 8, 'attacking' : 5, 'midfield' : 6, 'goalkeeping' : 9}, ... {'name' : 'bob', 'defense' : 5, 'attacking' :

Re: Finding attributes in a list

2005-03-29 Thread Bengt Richter
On Tue, 29 Mar 2005 11:29:33 -0700, Steven Bethard [EMAIL PROTECTED] wrote: infidel wrote: You can use the new 'sorted' built-in function and custom compare functions to return lists of players sorted according to any criteria: players = [ ... {'name' : 'joe', 'defense' : 8, 'attacking'