En Wed, 02 May 2007 12:16:56 -0300, Marc 'BlackJack' Rintsch
<[EMAIL PROTECTED]> escribió:
> In <[EMAIL PROTECTED]>, jocknerd
> wrote:
>
>> The biggest difference in my two apps is the C app uses linked lists.
>> I feel my Python app is doing too many lookups which is causing the
>> bottleneck.
>
> Then replace those linear searches you wrote in Python with a dictionary.
As an example: using a Team object instead of a dictionary, and using
teamlist (not a good name now) as a dictionary of Team objects indexed by
name:
def lookupTeam (teamname):
team = teamlist.get(teamname)
if team is None:
teamlist[teamname] = team = Team(teamname)
return team
def updateTeamStats (tname1, score1, tname2, score2):
team1 = lookupTeam (tname1)
team2 = lookupTeam (tname2)
team1.pf += score1
team1.pa += score2
if (score1 > score2):
team1.won += 1
elif (score1 < score2):
team1.lost += 1
else:
team1.tied += 1
team2.pf += score2
team2.pa += score1
if (score1 < score2):
team2.won += 1
elif (score1 > score2):
team2.lost += 1
else:
team2.tied += 1
Then you should realize that those last two blocks are too similar, and
you can make a function of it. And then you realize that in fact they act
on a Team object, so you should make a Team method...
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list