-
Notifications
You must be signed in to change notification settings - Fork 21
Ada-ac2 Ocelots Soumya S #12
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
base: main
Are you sure you want to change the base?
Conversation
…e_01 and test_wave_02 pass
…t_category() and __str__() methods. They all are child classes of item.py. Implemented condition_description in item.py. All tests in test_wave_05.py are passing.
…y() in vendor.py. Reversed the condition descriptions in item.py. All tests in test_wave_06.py are passing.
…ms() methods in vendor.py. All tests in test_wave_07.py are passing. All integration testes are passing
…ion_description()
| class Decor(Item): | ||
| def __init__(self, id=None, width=0, length=0, condition=0): | ||
| super().__init__(id, condition) | ||
| self.width = width if width else 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 use of ternary operators
| def __str__(self): | ||
| return f"An object of type {self.get_category()} with id {self.id}" | ||
|
|
||
| def condition_description(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.
Well organized code! At this point, you might see that a dict could be an alternative. And, has O(1) lookup time. In the worse case, it would take O(n) -- for n conditions -- to fall through to the last condition case with the if/else structure. :)
| def __init__(self, inventory=None): | ||
| self.inventory = inventory if inventory else [] | ||
|
|
||
| if not isinstance(self.inventory, list): |
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 error checking
| def get_by_id(self, id): | ||
| if not id or not self.inventory: | ||
| return None | ||
| return next((item for item in self.inventory if item.id == id), None) |
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.
excellent list comprehension!
| return True | ||
|
|
||
| def swap_first_item(self, other_vendor): | ||
| if not self or not other_vendor: |
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 example of guard statements. No need to indent the rest of the function as an else block after the returns. Clean.
| category_items = self.get_by_category(category) | ||
| if not category_items: | ||
| return None | ||
| return max(category_items, key=lambda item: item.condition) |
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 use of max for this!
No description provided.