Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 2

My first text(Tweeter) mining Python code ERROR

Solved! Go to Solution.

Can someone help please, I am trying to extract some tweets and then perform some basic analysis. I am encountering an error and i suspect its around the below section of the code:


I defined a function called word_in_text(word, text). This function return True if a word is found in text, otherwise it returns False


def word_in_text(word, text):
    word = word.lower()
    text = [item.lower() for item in tweet]

    match =, text)


I get the following ERROR

File "*:\*\*\Anaconda3\lib\", line 183, in search
return _compile(pattern, flags).search(string)

TypeError: expected string or bytes-like object


Thank you

1 Reply
Commander Lvl 3
Message 2 of 2

Re: My first text(Tweeter) mining Python code ERROR

Hi and welcome @BinTEPO ,


To match using the package that provides regular expressions, you must first craft a regular expression. Here are some handy tools:



After catching up on that and getting to know regular expressions you should be able to re-write the function to let it perform how you'd like to.


I know it's quite a bit to learn but it's pretty fun and if you're performing analysis on Tweets regular expressions will come in handy!


As always, just post back if you encounter any problems.

- Mark