Skip to content

Conversation

@smysh
Copy link

@smysh smysh commented Dec 9, 2022

No description provided.

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

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):

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):

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)

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:

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)

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!

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