-
Notifications
You must be signed in to change notification settings - Fork 103
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
Ruby - Ruth M #75
base: main
Are you sure you want to change the base?
Ruby - Ruth M #75
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yellow 🟡. As you know, wave 6 isn't complete, but everything else looks great!
You're almost there with Wave 6, too! get_best_by_category
just needs some tweaks to get working, then you can use that and swap_items
to finish off swap_best_by_category
. You're not required to resubmit, but if you are looking for practice later, I recommend coming back to this!
@@ -2,7 +2,7 @@ | |||
from swap_meet.vendor import Vendor | |||
from swap_meet.item import Item | |||
|
|||
@pytest.mark.skip | |||
# @pytest.mark.skip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] you can remove these
if self.condition == 0: | ||
return 'this is Garbage!' | ||
elif 1 <= self.condition < 2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful about statements like this. They sometimes have unexpected behavior. Prefer writing out the logical expression:
elif 1 <= self.condition and self.condition < 2:
Also, worth noting: what happens if self.condition
is between 0 and 1?
id = int(uuid.uuid4()) | ||
self.id = id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A ternary is also fine here:
self.id = id if id else uuid.uuid4().int
|
||
self.add(other_vendor.inventory[0]) | ||
|
||
self.remove(self.inventory[0]) | ||
|
||
other_vendor.remove(other_vendor.inventory[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] No need to space between each function call
|
||
for stuff in self.inventory: | ||
if stuff.get_category() == category: | ||
objects.append(stuff) | ||
|
||
return objects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice this pattern of:
result_list = []
for element in source_list:
if some_condition(element):
result_list.append(element)
can be rewritten using a list comprehension as:
result_list = [element for element in source_list if some_condition(element)]
Which here would look like:
objects = [stuff for stuff in self.inventory if stuff.get_category() == category]
return objects
At first, this may seem more difficult to read, but comprehensions are a very common python style, so I encourage y’all to try working with them!
def get_by_category(self,category): | ||
|
||
self.category = category |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful here! It's probably unexpected if calling a get
function modifies the instance object. Nothing is wrong with the class as-is because you don't use self.category
in any other method. If you did use it elsewhere, this could have unintended side effects.
if stuff.condition_description() < best_condition: | ||
best_condition = category_condition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're on the right track! Some things to think about...
- You want to get the things from the
self.inventory
that have a specificcategory_condition
. You wrote a method above this that can do that! - Your "best" condition is the highest one, not the lowest
- You want to keep track of the best condition and the best stuff you've seen, too.
With those things in mind, see if you can come up with how to modify this code. If you still get stuck, here's a snippet that I think might help get you there: https://gist.github.com/mmcknett-ada/26444ed29c91927c05dc7d577d5bd67e
No description provided.