Open
Conversation
| class Item: | ||
| pass No newline at end of file | ||
| def __init__(self, id=None, condition=0): | ||
| self.id = id if id else uuid.uuid4().int |
| def condition_description(self) : | ||
| # Make sure condition is a integer between zero and five | ||
| condition = max(0, min(5, math.floor(self.condition))) | ||
| description_dict = { |
There was a problem hiding this comment.
great use of a dict here. And if/else block would take O(n) worse case to fall through to the last condition!
Plus, nice formatting of the contents of the dict here
| cur_best_condition = None | ||
| for item in self.inventory: | ||
| if item.get_category() == category: | ||
| if cur_best_item is None or item.condition > cur_best_condition: |
There was a problem hiding this comment.
Okay, this is clean code that only loops through the whole thing once. In a more complex project, you can probably see how we could use things like filter to pull specific sets out of the inventory. Well done, though!
| def display_inventory(self, category=""): | ||
| # When there is no assigned category, it should display all inventory | ||
| assigned_category_inventory = list(filter( | ||
| lambda item: item.get_category() == category if category else True, |
There was a problem hiding this comment.
nice use of a lambda. with a ternary operator, too!
|
|
||
| return self.swap_by_id(other_vendor, my_item_id, their_item_id) | ||
|
|
||
| def swap_similar_items(self, other_vendor, my_item): |
There was a problem hiding this comment.
Nice use of OOP-based similarity enhancement!
| def swap_similar_items(self, other_vendor, my_item): | ||
| their_inventory = other_vendor.get_by_category(my_item.get_category()) | ||
|
|
||
| final_candidates = list(filter(lambda item: my_item.is_similar(item), their_inventory)) |
There was a problem hiding this comment.
Ah, and there's filter. Good use of it here!
|
|
||
| assert one_condition_description != five_condition_description | ||
|
|
||
| def test_item_condition_higher_than_five_return_five(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.