Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharks - Sana Pournaghshband #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sanakakadan22
Copy link

No description provided.

Copy link

@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 🟢 !

from swap_meet.item import Item

class Clothing(Item):

Choose a reason for hiding this comment

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

👍

@@ -1,2 +1,15 @@
class Item:

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 on lines +3 to +6
self.inventory = []
else:
self.inventory = inventory

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 on lines +13 to +16
self.inventory.remove(item)
return item
return False

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 on lines +19 to +24
for item in self.inventory:
if category == item.category:
item_list.append(item)

return item_list

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 on lines +27 to +30
return False
if their_item not in vendor.inventory:
return False

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

return True

def swap_first_item(self, vendor: 'Vendor'):

Choose a reason for hiding this comment

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

👍

Comment on lines +51 to +53
if item.category == category:
category_items.append(item)

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 on lines +61 to +64
their_item = other.get_best_by_category(my_priority)

return self.swap_items(other, my_item, their_item)

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

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