"How to Make a Website" was retired on March 24, 2020. You are now viewing the recommended replacement.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Python Comprehensions!
You have completed Python Comprehensions!
How did you go? In this video I’ll walk through what I did to complete these challenges.
Solutions
Challenge 1
leap_years = [year for year in range(1901, 2001) if year%4==0]
Challenge 2
the_simpsons = [f"{character} Simpson" for character in characters if character in simpsons]
Challenge 3
word_lengths = {word: len(word) for word in words if len(word)>=5}
Challenge 4
ages_next_year = {person: age+1 if person!='Danny' else age for (person, age) in ages.items()}
Challenge 5
vowels = {letter for letter in statement.lower() if letter in 'aeiou'}
Challenge 6
overlap = {food for food in fruits if food in vegetables}
Challenge 7
def format_name(honorific, candidate):
return honorific + " " + candidate.get('name').split()[-1]
graduates = [format_name("Professor", candidate) if candidate.get('score')>=90 else format_name("Doctor", candidate) for candidate in phd_candidates if candidate.get('score') >=70]
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up