-
Notifications
You must be signed in to change notification settings - Fork 113
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
C17 Otters Vera Sazonova #93
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Vera! Your submission has been scored as green. Please check your code to see the comments I left. Let me know if you have any questions. Nice work! :)
|
||
def add(self,item): | ||
'''Instance method add, which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice usage of docstrings! 👏
'''Instance method implement swaping process first item''' | ||
|
||
if len(self.inventory) == 0 or len(friend.inventory) == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small note - it's more Pythonic to check if a list is empty by doing if not list
rather than if len(list) == 0
if len(self.inventory) == 0 or len(friend.inventory) == 0: | ||
return False | ||
self.swap_items(friend,self.inventory[0],friend.inventory[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice usage of self.swap_items()
✨
|
||
best_dict_category = {} | ||
best_dict_category[consider_category] = 0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small note - you can create a dictionary and specify its values in the same line. So, line 64 could be best_dict_category = {consider_category: 0.0}
and you wouldn't need line 65.
# matching category is key and value is rate. Setup first element | ||
# of dictionary like max and matching other rate, if higher add to dict | ||
for category_from_inv in self.inventory: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small note - variable names should describe the data they are holding. category_from_inv
is holding items, not their categories. If you were working in a team of developers, this could cause confusion for other people. Something you might find helpful - before I consider any code I write finished, I like to think about how easy it would be for someone else to pick up my code and understand it.
if count == 0: | ||
return None | ||
return best_category |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something to consider - Python doesn't create a local scope for loops which is why you can return best_category
outside of the loop. However, most other languages don't allow access to variables created inside of loops. Going forward, it could be good to treat loops as having a local scope to build that habit.
in a certain category''' | ||
|
||
if len(self.inventory) and len(other.inventory) != 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Careful with how you are combining conditional statements with
and
. The!= 0
check isn't being applied tolen(self.inventory)
. In order to apply it to both lists, this should be written asif len(self.inventory) != 0 and len(other.inventory) != 0:
. Python knowslen(self.inventory)
evaluates to a truthy value, which is why your version still works. - This line of code can be simplified to be
if self.inventory and other.inventory:
because Python knows to evaluate an empty list as False. This way is also considered more Pythonic. - Consider if this conditional statement is even necessary. Input validation is great but sometimes the rest of the code is set up in a way that it isn't necessary to validate the input. Does the
get_best_by_category()
method know how to handle empty lists? If so, is it necessary to check that the list isn't empty here?
def __init__(self, category = None, condition = 0.0): | ||
if category is None: | ||
category = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strings are immutable objects so it's safe to set an empty string as a default value in your parameters :)
|
||
|
||
def __repr__(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love that you're using the repr()
function!
@pytest.mark.skip | ||
@pytest.mark.integration_test | ||
# @pytest.mark.skip | ||
# @pytest.mark.integration_test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, don't worry about commenting out @pytest.mark.integration
. This decorator just specifies that these tests are integration tests so they should run after all the unit tests have been executed. :)
No description provided.