Skip to content

Ada-ac2 Ocelots Soumya S#12

Open
smysh wants to merge 12 commits intoada-ac2:mainfrom
smysh:main
Open

Ada-ac2 Ocelots Soumya S#12
smysh wants to merge 12 commits intoada-ac2:mainfrom
smysh:main

Conversation

@smysh
Copy link
Copy Markdown

@smysh smysh commented Dec 9, 2022

No description provided.

Comment thread swap_meet/decor.py
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
Copy link
Copy Markdown

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

Comment thread swap_meet/item.py
def __str__(self):
return f"An object of type {self.get_category()} with id {self.id}"

def condition_description(self):
Copy link
Copy Markdown

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

Comment thread swap_meet/vendor.py
def __init__(self, inventory=None):
self.inventory = inventory if inventory else []

if not isinstance(self.inventory, list):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nice error checking

Comment thread swap_meet/vendor.py
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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

excellent list comprehension!

Comment thread swap_meet/vendor.py
return True

def swap_first_item(self, other_vendor):
if not self or not other_vendor:
Copy link
Copy Markdown

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.

Comment thread swap_meet/vendor.py
category_items = self.get_by_category(category)
if not category_items:
return None
return max(category_items, key=lambda item: item.condition)
Copy link
Copy Markdown

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