Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCC01 ryanh153 #571

Merged
merged 5 commits into from
Sep 24, 2019
Merged

PCC01 ryanh153 #571

merged 5 commits into from
Sep 24, 2019

Conversation

ryanh153
Copy link
Contributor

ATTENTION: before clicking "Create Pull Request" please submit some meta data, thanks!

Difficulty level (1-10): []
Estimated time spent (hours): []
Completed (yes/no): []
I stretched my coding skills (if yes what did you learn?): []
Other feedback (what can we improve?): []

@ryanh153
Copy link
Contributor Author

Difficulty level (1-10): [3]
Estimated time spent (hours): [1]
Completed (yes/no): [Yes]
I stretched my coding skills (if yes what did you learn?): [Refreshed reading in files and practiced list comprehension (always good). ]
Other feedback (what can we improve?): []

Copy link
Collaborator

@pmayd pmayd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to fix a few non-Pythonic places, but in general great job!

with open(DICTIONARY,'r') as dicFile:
dictionary = dicFile.readlines()

dictionary = [word.strip() for word in dictionary]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a minor issue but the name "dictionary" implies to the reader that the content of that variable is a Python dictionary, but it is a list. This is of course in this exercise a little bit hard to avoid, but in general, its a good way to have the type of a variable in the name, for example a list_of_words is a Python list holding words, which the reader expects then to be strings.

"""Calculate the value of the word entered into function
using imported constant mapping LETTER_SCORES"""
def calc_word_value(word):
return sum([LETTER_SCORES[char] for char in word.upper() if char in LETTER_SCORES.keys()])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. in Python char in dict.keys() is identical to char in dict so you can ommit the call to keys()
  2. Because you don't need the list for further processing, better to use a generator inside the sum, so there is no need to calculate first the score of all letters. Of course here the memory consumption is rather low and limited to the maximum length of a given word, but nevertheless, good style to avoid lists when you dont explitly need them

"""Calculate the word with the max value, can receive a list
of words as arg, if none provided uses default DICTIONARY"""
def max_word_value(words=None):
if words == None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is correct, but not the Pythonic way to do things. You have to better options:

  1. Use the Python special "is": if words is None which avoids the equal operator
  2. Even better, use just if words. This is a shorthand evaluation that is True either for empty lists or None so if words: is a good way to prove for empty or nonexisting variables

return words[scores.index(max(scores))]

if __name__ == "__main__":
pass # run unittests to validate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could solve this little comment by replacing pass with unittest.main()

This file is not part of your solution and rather big. You don't have to commit files of the original challenge :)
Again, you don't have to add template files to your solution, just your solution :)
This file is part of the challenge and not your code so I deleted it from the PR
Tests are part of the challenge and not your contribution so I deleted them from the pR :)
@pmayd pmayd merged commit acfa185 into pybites:community Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants