Skip to content

Sharks - Sana Pournaghshband#103

Open
sanakakadan22 wants to merge 1 commit intoada-c17:masterfrom
sanakakadan22:master
Open

Sharks - Sana Pournaghshband#103
sanakakadan22 wants to merge 1 commit intoada-c17:masterfrom
sanakakadan22:master

Conversation

@sanakakadan22
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@yangashley yangashley left a comment

Choose a reason for hiding this comment

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

Nice job, Sana!

All required waves are complete and all required tests are passing! Your code is well organized and you used descriptive variable names. Your general approaches are good, and you're off to a good start with OOP.

I called out some places where you can reverse your logic so you implement a guard clause instead of if/else. This will make your python code more idiomatic. Avoiding unnecessary indenting (by using guard clauses), and checking conditions making use of pythons ideas about truthy and falsy can communicate your intent to other python developers very quickly.

I also pointed out where you can use list comprehension and list destructuring if you're up for it.

Well done 🟢 !

Comment thread swap_meet/clothing.py
pass No newline at end of file
from swap_meet.item import Item

class Clothing(Item):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread swap_meet/item.py
@@ -1,2 +1,15 @@
class Item:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Item class looks good!

Comment thread swap_meet/vendor.py
Comment on lines +3 to +6
if not inventory:
self.inventory = []
else:
self.inventory = inventory
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you have a guard clause on line 3, you don't need the dangling else on line 5.
You could write it like:

if not inventory:
    self.inventory = []

self.inventory = inventory

You might also see this written as a ternary:

my_var = "some value" if some_condition else "other value"

In this situation, that would look like

self.inventory = [] if inventory is None else inventory

Comment thread swap_meet/vendor.py
Comment on lines +13 to +16
if item in self.inventory:
self.inventory.remove(item)
return item
return False
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A more explicit way to return False would be to use a guard clause instead doing it in the main body of the method.

if item not in self.inventory:
     return False

self.inventory.remove(item)
return item

Another approach we could take is to try to remove the item directly, and handle the ValueError that occurs if it's not there, and return False to handle it (try/except)

Comment thread swap_meet/vendor.py
Comment on lines +19 to +24
item_list = []
for item in self.inventory:
if category == item.category:
item_list.append(item)

return item_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.

Looks good.

This method is a great candidate for using list comprehension if you want to refactor it since our conditional statement we check is pretty simple.

General syntax for list comp:

result_list = [element for element in source_list if some_condition(element)]

Which here would look like:

item_list = [item for item in self.inventory if item.category == category]

You can also forgo saving the list to the variable item_list and do something like:

def get_by_category(self, category):
    return [item for item in self.inventory if item.category == category]

Comment thread swap_meet/vendor.py
Comment on lines +27 to +30
if my_item not in self.inventory:
return False
if their_item not in vendor.inventory:
return False
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 guard clause. You can combine lines 27 and 29 like:

if my_item not in self.inventory and their_item not in vendor.inventory:
    return false

Comment thread swap_meet/vendor.py
self.add(their_item)
return True

def swap_first_item(self, vendor: '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.

👍

Comment thread swap_meet/vendor.py
Comment on lines +51 to +53
for item in self.inventory:
if item.category == category:
category_items.append(item)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider reusing your get_by_category method that you already defined so you don't have to loop and add to a list again.

Comment thread swap_meet/vendor.py
Comment on lines +61 to +64
my_item = self.get_best_by_category(their_priority)
their_item = other.get_best_by_category(my_priority)

return self.swap_items(other, my_item, their_item)
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 work reusing your function get_best_by_category.

Also, way to leverage the validation checks in swap_items method on line 27 and 29 in Vendor.py.

I also like that you return the Boolean value from swap_items so you didn't have to explicitly return True or return False here in swap_best_by_category.

Comment on lines +252 to +259
assert len(tai.inventory) ==3
assert len(jesse.inventory) == 3
assert item_a in tai.inventory
assert item_b in tai.inventory
assert item_c in tai.inventory
assert item_d in jesse.inventory
assert item_e in jesse.inventory
assert item_f in jesse.inventory
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can combine lines 252 and 253 if you want:
assert len(tai.inventory) == 3 and len(jesse.inventory) == 3

You can use list destructing like this too - a pythonic way of doing it:

assert [item_a, item_b, item_c] == tai.inventory
assert [item_d, item_e, item_f] == jesse.inventory

https://medium.com/@umaramanat66/destructuring-list-in-python-like-javascript-f7d4c0968538

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