FAQ: Code Challenge: Queries - Code Challenge 8

This community-built FAQ covers the “Code Challenge 8” exercise from the lesson “Code Challenge: Queries”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development
Data Science

FAQs on the exercise Code Challenge 8

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I feel like the answer should be updated to be ‘% bitcoin %’ OR ‘%bitcoin %’ OR ‘% bitcoin’ since the current answer also matches ‘bitcoins’ and ‘BITCOINS’ (and other variations). Obviously, I was over-thinking this but the question does say to search for the word ‘bitcoin’ and not the phrase.

% stands for zero or more characters, does it not? If so it should match any phrase with ‘bitcoin’ in it, regardless whether surrounded by other characters, including white space, or not. Am I wrong about this?

1 Like

Can we check for the word in a row at a particular position like 5th or 6th word in the title of the article ??

Not sure if I get your question, but on the surface, yes we can check any position by subscripting it.

Say our variable containing the title is named, title and we are looking to see if ‘word’ is at the 5th or 6th position…

title_split = title.split()

if title[4] == 'word' or title[5] == 'word':

If we are fairly certain there are no repeated words, we could query the index of the target, 'word'

title.index('word')

Eg.

>>> title = "A quick brown fox jumps over the lazy dog".split()
>>> title.index('fox')
3
>>> title.index('cat')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: 'cat' is not in list
>>> 

We could check if the word is in the list, and if it is, then we can query the index.

if 'cat' in title:
    print (title.index('cat'))
else:
    print ('cat' not found in 'title')
1 Like

Capture 02