Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJon C
6,512 PointsCode accepted but unsure why.
Why is .contains() needed for Challenge.name but not for Challenge.language? Also, why can't == be used on Challenge.name?
I was messing around with .contains() and it returns ['%Chalkers%'] While == returns ['Chalkers']
Does the %% mean something in peewee/sqlite?
from models import Challenge
def create_challenge(name, language, steps=1):
Challenge.create(name=name,
language=language,
steps=steps)
def search_challenges(name, language):
return Challenge.select().where(Challenge.name.contains(name), Challenge.language == language)
1 Answer
Steven Parker
231,269 PointsThe constraints are spelled out in the challenge. It asks you to return the items "where the name field contains name argument and the language field is equal to the language argument". So they specifically want you to accept names that partially match (contain) the argument, but a language that is an exact match (==).
The % symbol is commonly used in SQL as a wildcard. So if you had a filter in SQL that said name LIKE '%mas%', it would match any name that contained "mas", including "Dumas" or "Lemassey".
Jon C
6,512 PointsJon C
6,512 PointsOh, partial match! Thanks.