Character classes

Screen Link:

My Code:

pattern = "\[video+\]" 
tag_titles = titles.str.contains(pattern)
tag_count = tag_titles.sum() 

What I expected to happen:

What actually happened:

So the correct answer is 444, but I end up getting 111. I am still a little bit stuck on how to write down the pattern inside of the brackets
Thank you

You have to count the number of titles that contain a tag, i.e., not only video but others like
pdf, Python , and 2018 as well.
And, I think you will have to use .+ as well in the pattern, in order to capture the sequences containing space or punctuation character.
So, change the pattern to the following and try it out
pattern = "\[\w+.+\]"

Let now whether it worked.


Sounds good. I will try it now and let you know. Thanks!

So it worked with pattern = "\[\w+.+\]" but I got 469. However, I got rid of the .+ part and I ended up getting the right answer which is 444.

1 Like