Conversation
| class Item: | ||
| pass No newline at end of file | ||
| def __init__(self, id=None, condition=0): | ||
| self.id = uuid.uuid1().int if not id else id |
There was a problem hiding this comment.
nice example of a ternary operator
| self.condition = condition | ||
|
|
||
| def get_category(self): | ||
| return self.__class__.__name__ |
| return f"An object of type {self.get_category()} with id {self.id}" | ||
|
|
||
| def condition_description(self): | ||
| descriptions = {0: "torn", 1: "a bit shredded", 2: "defs used", 3: "lightly used", 4: "near perfect", 5: "perf",} |
There was a problem hiding this comment.
minor suggestion: formatting this dictionary on multiple lines for readably
| return f"An object of type {self.get_category()} with id {self.id}" | ||
|
|
||
| def condition_description(self): | ||
| descriptions = {0: "torn", 1: "a bit shredded", 2: "defs used", 3: "lightly used", 4: "near perfect", 5: "perf",} |
There was a problem hiding this comment.
nice use of a dict to store this info, vs an if statement. You can imagine that a long if-else statement would take worst case O(N) to fall through to the last condition. ;)
| return None | ||
|
|
||
| def swap_items(self, other_vendor, my_item, their_item): | ||
| if my_item == their_item: |
There was a problem hiding this comment.
nice use of guard statements to return as fast as possible before executing other code; I appreciate that you didn't indent the rest of the function as an else code block; no need as the code doesn't continue past the returns. Yours is the cleaner style.
| if not self.inventory: | ||
| return [] | ||
|
|
||
| item_category_list = list(filter(lambda item: item.get_category() == category, self.inventory)) |
| if not item_category_list: | ||
| return None | ||
|
|
||
| max_item = max(item_category_list, key=lambda item: item.condition) |
There was a problem hiding this comment.
ahhhh well done, nice to see max used here!
| their_priority_item_in_my_inventory = self.get_best_by_category(their_priority) | ||
| my_priority_item_in_their_inventory = other_vendor.get_best_by_category(my_priority) | ||
| if my_priority_item_in_their_inventory == None or their_priority_item_in_my_inventory == None: | ||
| False |
There was a problem hiding this comment.
@diarreola confused about this False on a standalone line. return False?
There was a problem hiding this comment.
me too 🤔, I think I did mean to have return False
There was a problem hiding this comment.
Nodding. Thank you for reviewing the feedback and following up! I appreciate that!
| return | ||
|
|
||
| print_inventory(category_based_inventory) | ||
| return |
There was a problem hiding this comment.
no need for this return at the end of the function :)
:)