Scrabble_score


#1

Hi,
just wondering if you could give me some pointers on how to make my code better? I've been looking through the forums and nobody did it like this.

def scrabble_score(word):
    total = []
    for x in word.lower():
        total.append(score[x])
    return sum(total)

It works but I don't know if it is actually the best way to do it and I was wondering for some pointers on best practice etc.
Thanks

Split from Scrabble_score Minor Doubt


Scrabble_score Minor Doubt
#2

i would choice terablaster94788 approach, your approach means i first have to construct a list into memory, before taking the sum, while terablaster his approach just does simple math operations

In such a small program, there won't be much difference between these two approaches, both are fine


#3

So I'm guessing that in larger programs this would be an issue and would take up large amounts of memory?
Thank you for you help by the way.


#4

Yes, you are right. Besides you take two steps:

creating list
doing math

where terablaster takes one step:

doing math

its a small difference. If your lists don't get very big, its no problem.


#5

Thank you for your help! :slight_smile:


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.