Skip to content

"SHARKS Raha MR"#102

Open
Ramora6627 wants to merge 9 commits into
ada-c17:masterfrom
Ramora6627:master
Open

"SHARKS Raha MR"#102
Ramora6627 wants to merge 9 commits into
ada-c17:masterfrom
Ramora6627:master

Conversation

@Ramora6627
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@audreyandoy audreyandoy left a comment

Choose a reason for hiding this comment

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

Great work Raha! You hit all the learning goals for this project and all tests are passing. You have earned a well-deserved 🟢 grade on this project 🦈✨

I added comments to your PR primarily on ways to refactor your code, improve tests, and improve the readability of your code. In the future, I'd like to see more docstrings in your functions. Docstrings are a great way of leaving notes to your future self about your approach to writing these functions.

In future projects, I'd like to see you use more for in loops when iterating through the values of a list and to use more descriptive variable names.

Feel free to refactor and improve on this project and do let me know if you want me to take another look for fun 😄

Keep up the great work! ✨

Comment thread tests/test_wave_01.py
Comment on lines +121 to +122
assert updated_data["watched"][0]["title"] is MOVIE_TITLE_1
assert updated_data["watched"][0]["genre"] is GENRE_1
Copy link
Copy Markdown

@audreyandoy audreyandoy Mar 31, 2022

Choose a reason for hiding this comment

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

This is a much-needed change in our tests but our test asserts should use == instead of is.`

== checks for value equality while is checks for reference equality (if both references point to the same object in memory).

is is typically used when we check whether a value equates to None i.e. "if user_data is None".

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So in this case the assert should look like:

Suggested change
assert updated_data["watched"][0]["title"] is MOVIE_TITLE_1
assert updated_data["watched"][0]["genre"] is GENRE_1
assert updated_data["watched"][0]["title"] == MOVIE_TITLE_1
assert updated_data["watched"][0]["genre"] == GENRE_1

Comment thread tests/test_wave_01.py
Comment on lines +145 to +146
assert updated_data["watched"][1]is HORROR_1
assert updated_data["watched"][0]is FANTASY_2
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's also more pythonic to have spaces between expressions, keywords, and operators:

    assert updated_data["watched"][1] == HORROR_1
    assert updated_data["watched"][0] == FANTASY_2

Comment thread tests/test_wave_03.py
Comment on lines +57 to +60
assert INTRIGUE_3 in friends_unique_movies
assert HORROR_1 in friends_unique_movies
assert FANTASY_4 in friends_unique_movies
assert FANTASY_2 not in friends_unique_movies
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 tests/test_wave_05.py
Comment on lines +55 to +59
# Act
recommendations = get_new_rec_by_genre(sonyas_data)

# Assert
assert len(recommendations) == 0
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 viewing_party/party.py
Comment on lines +5 to +11
movie_table = {}

if title and genre and rating:
movie_table["title"] = title
movie_table["genre"] = genre
movie_table["rating"] = rating
return movie_table
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 work Raha! I like how you added key-value pairs by first checking for truthiness.

Another way to write this function is by using a guard clause and building the dictionary directly in the return statement. This allows your function to exit early when falsy values are passed in and reduces the amount of nested code we have, allowing the primary purpose of the function to be slightly easier to read.

def create_movie(title, genre, rating):
   if not title or not genre or not rating:
       return None
       
   return { 
           "title": title, 
           "genre": genre, 
           "rating": rating 
       }

Comment thread viewing_party/party.py
Comment on lines +138 to +139
favorite = Counter(genre)
fave_max = max(favorite, key=favorite.get)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The Counter collection is handy but we could use get_most_watched_genre() as a helper function.

Comment thread viewing_party/party.py
fave_max = max(favorite, key=favorite.get)
results = []

for i in range(len(list(friends_watched[0]["watched"]))):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Loop variables should also be descriptive names. i is too generic. Having descriptive names improves readability and helps us understand our code when we revisit it in months or years later.

Comment thread viewing_party/party.py
return []
favorites = user_data["favorites"]

all = []
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

all can also be mistaken as the all() function. Perhaps all_movies_list or all_movies would be a good name for this scenario?

Comment thread viewing_party/party.py
Comment on lines +158 to +160
for a in range(len(friends_watched)):
for b in range(len(friends_watched[a]["watched"])):
all.append(friends_watched[a]["watched"][b]["title"])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

How might this look with a for in loop/

Comment thread viewing_party/party.py
Comment on lines +168 to +170
c = [x for x in favorites if x not in mutual]

return c
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 list comprehension but what does c represent?

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