Question

def contains_hashtag(valid_tweet: str, tweet_word:str) -> bool: '''Return True if the valid tweet contains the tweet word,...

def contains_hashtag(valid_tweet: str, tweet_word:str) -> bool:
'''Return True if the valid tweet contains the tweet word, with a
hashtag at the beginning. Tweet can contain multiple tweet words.

>>>contains_hashtag('I like #csc108', 'csc108')
True
>>>contains_hashtag('I like #csc108', 'csc')
False
>>>contains_hashtag('I like #csc108, #mat137, and #phl101', 'csc108')
True

pls finish this function by using python string method(do not use advance methods)

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def contains_hashtag(valid_tweet: str, tweet_word:str) -> bool:
    '''Return True if the valid tweet contains the tweet word, with a
    hashtag at the beginning. Tweet can contain multiple tweet words.
    '''
    key = "#"+tweet_word
    return key in valid_tweet.replace(",","").split(' ')


# Testing
print(contains_hashtag('I like #csc108', 'csc108'))
print(contains_hashtag('I like #csc108', 'csc'))
print(contains_hashtag('I like #csc108, #mat137, and #phl101', 'csc108'))

Add a comment
Know the answer?
Add Answer to:
def contains_hashtag(valid_tweet: str, tweet_word:str) -> bool: '''Return True if the valid tweet contains the tweet word,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT