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

Tigers - Kindra Greenawalt #146

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

kkgre257
Copy link

No description provided.

Copy link

@spitsfire spitsfire left a comment

Choose a reason for hiding this comment

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

Great job, Kindra! You had creative ideas that helped you solve each wave, so congrats passing all the tests.

I've added some feedback throughout your project to point out some places we can refactor in order to follow common conventions and standard practices when it comes to Python.

Things to consider as you work on future projects:

  • for i in range loops are good when you need to access or use the index position value in your program. If you are going through a list of objects or a collection of values that have a common theme (list of movies, list of dog breeds, etc.), consider directly iterating over the list like for genre in genre_list
  • for loops will increment on their own. We don't need to manually increment i with i += 1
  • if we are returning one value in a function, we don't need parentheses

Comment on lines +12 to +14
if None in information:
return None
else:

Choose a reason for hiding this comment

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

Think about putting this at the top of the function first. This way it handles the edge cases or special cases quickly and gets out, rather than having that dangling else at the end.

This arrangement is referred to as a guard clause or a guard condition. Notice that it lets us move the main focus of the function (creating the new dict) out of an indented block, letting it stand out more clearly.

It also saves us from creating space in memory, defining variables, etc. that we are simply going to throw away because the parameters didn't meet our rules.

    information = [title,genre,rating]
    if None in information:
        return None
    
# the rest of your code here

Comment on lines +11 to +12
information = [title,genre,rating]
if None in information:

Choose a reason for hiding this comment

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

very creative way to check if all variables are valid. if... in has a for loop running under the hood to check each item in the list, so even though it looks cleaner than several compound conditions, it may not be as efficient.

Hard to say, though! The data we use is so small, it certainly doesn't matter on this scale!

Comment on lines +6 to +9
movie_dict = {}
movie_dict["title"]= title
movie_dict["genre"] = genre
movie_dict["rating"] = rating

Choose a reason for hiding this comment

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

this works just fine! We could also do this all at once:

Suggested change
movie_dict = {}
movie_dict["title"]= title
movie_dict["genre"] = genre
movie_dict["rating"] = rating
movie_dict = {
movie_dict["title"]: title,
movie_dict["genre"]: genre,
movie_dict["rating"]: rating
}

Now, obviously this isn't one line like this, so we aren't saving space. But we can do it all in one expression instead of 4.

return movie_dict

def add_to_watched(user_data, movie):
user_data["watched"] = [movie]

Choose a reason for hiding this comment

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

careful here! You are re-assigning user_data["watched"] value, not appending to the list already inside.

What if this same user adds another movie to "watched"? It would overwrite the first movie with the new movie, instead of appending it to the list already declared in user_data["watched"]

Suggested change
user_data["watched"] = [movie]
user_data["watched"].append(movie)

Comment on lines +22 to +23
user_data["watchlist"] = [movie]
return user_data

Choose a reason for hiding this comment

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

same as above! We want to append to "watchlist" list, not overwrite it with a new one


# -----------------------------------------
# ------------- WAVE 4 --------------------
# -----------------------------------------

def get_available_recs(user_data):
movie_recs = []
list_of_movie_dictionaries_user_has_not_watched_but_friend_has = get_friends_unique_watched(user_data)

Choose a reason for hiding this comment

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

great job reusing functions!

movie_recs = []
list_of_movie_dictionaries_user_has_not_watched_but_friend_has = get_friends_unique_watched(user_data)
for subscription in user_data["subscriptions"]:
for dictionary in list_of_movie_dictionaries_user_has_not_watched_but_friend_has:

Choose a reason for hiding this comment

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

what is dictionary represent in this instance? could we call it something more descriptive, like movie?

Comment on lines +162 to +163
if users_most_frequently_watched_genre == None:
movie_recs_by_genre = []

Choose a reason for hiding this comment

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

I think we can get rid of this altogether since it is already set up as an empty list on line 160

if users_most_frequently_watched_genre == dictionary["genre"]:
movie_recs_by_genre.append(dictionary)

return(movie_recs_by_genre)

Choose a reason for hiding this comment

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

Suggested change
return(movie_recs_by_genre)
return movie_recs_by_genre

for dictionary in list_of_movie_dictionaries_user_has_watched_but_friends_have_not:
if favorite["title"] == dictionary["title"]:
movie_recs_from_favorites.append(dictionary)
return(movie_recs_from_favorites)

Choose a reason for hiding this comment

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

Suggested change
return(movie_recs_from_favorites)
return movie_recs_from_favorites

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