Skip to content

#Ocelots Megan Maple#22

Open
maple-megan333 wants to merge 4 commits intoada-ac2:mainfrom
maple-megan333:main
Open

#Ocelots Megan Maple#22
maple-megan333 wants to merge 4 commits intoada-ac2:mainfrom
maple-megan333:main

Conversation

@maple-megan333
Copy link
Copy Markdown

No description provided.

Comment thread swap_meet/item.py

#Instantiate with id, allowing custom or using UUID Int auto generate
def __init__(self, id=None, condition=None):
self.id = id if id is not None else uuid.uuid1().int
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 operator

Comment thread swap_meet/item.py
self.condition = condition if condition is not None else 0
#get the class name
def get_category(self):
return str(type(self).__name__)
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 python introspection!

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

#adding a condition description class to describe condition based on value of 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.

typo. "function", not "class"

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

#adding a condition description class to describe condition based on value of condition
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.

clever, but unnecessarily so here. A dict would have sufficed, and been O(1) lookup, vs O(n) to fall through n conditions in the worse case :)

Comment thread swap_meet/item.py
#adding a condition description class to describe condition based on value of condition
def condition_description(self):
case = lambda x: self.condition < x
if case(1): item_condition_desc = "Very Poor Indeed"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

love the descriptions, though! :D

Comment thread swap_meet/vendor.py
def remove(self, item_to_remove):
if item_to_remove not in self.inventory:
return None
self.inventory.remove(item_to_remove)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

great use of inventory.remove instead of re-implementing that code.

Comment thread swap_meet/vendor.py
if item_to_give not in self.inventory or item_to_get not in vendor_friend.inventory:
return False

vendor_friend.add(self.remove(item_to_give))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

concise! for debugging and maintenance, this could be on different lines. That said, you did do error checking above, so that ameliorates some of the chances that you'll hit an error here.

Comment thread swap_meet/vendor.py
#get items from inventory by catagory
def get_by_category(self, category_string):

return [item for item in self.inventory if item.get_category() == category_string]
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 use of list comprehension

Comment thread swap_meet/vendor.py

def get_best_by_category(self, category_string):
if self.get_by_category(category_string):
return max(self.get_by_category(category_string), 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.

Yay, using max plus lambda here!

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