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
  • def add_mention_exclusive(valid_tweet: str, tweet_word: str) -> str: ""Return if the potential tweet is valid, the original...

    def add_mention_exclusive(valid_tweet: str, tweet_word: str) -> str: ""Return if the potential tweet is valid, the original tweet contains the given tweet word, and the original tweet does not mention the given tweet word, the function should return the potential tweet. Otherwise, the function should return the original tweet. >>>add_mention_exclusive ('Go Raptors!', 'Raptors') 'Go Raptors! @Raptors' >>>add_mention_exclusive('Go @Raptors!', 'Raptors') 'Go @Raptors! if

  • def contains_song(title: str, filename: str) -> bool: ''' Return True iff title (the name of a...

    def contains_song(title: str, filename: str) -> bool: ''' Return True iff title (the name of a song as a string) is included in the file with of the given filename. '''

  • Python help def palindrome_word: ''' (str) -> bool The parameter is a string consisting only of...

    Python help def palindrome_word: ''' (str) -> bool The parameter is a string consisting only of lowercase alphabetic letters. It may or may not be a palindrome. Return True if and only if the parameter is a palindrome. The empty string is considered to be a palindrome. ''' def palindrom_phrase: ''' (str) -> bool The parameter is a string that may or may not be a palindrome. Return True if and only if the parameter is a palindrome, independent of...

  • class Bool(Expr): """A boolean constant literal. === Attributes === b: the value of the constant """...

    class Bool(Expr): """A boolean constant literal. === Attributes === b: the value of the constant """ b: bool def __init__(self, b: bool) -> None: """Initialize a new boolean constant.""" self.b = b # TODO: implement this method! def evaluate(self) -> Any: """Return the *value* of this expression. The returned value should the result of how this expression would be evaluated by the Python interpreter. >>> expr = Bool(True) >>> expr.evaluate() True """ return self.b def __str__(self) -> str: """Return a...

  • python function will Return True if string x contains 3 vowels in a row, in consecutive...

    python function will Return True if string x contains 3 vowels in a row, in consecutive locations, false otherwise. assuming that 'vowels' refer to the following lowercase lttrs: a,e,i,o,u programs fails partially, only allowed to use float, str, int, appen, split, strip, len, range def vowels_three(x): for i in range (o, len(x), 2): if x[i] not in ('a,e,i,o,u'): return False return True

  • def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or...

    def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or not "B" or not "C" or not "D" or not "E" or not "F" or not "G" or not "H" or not "I" or not "J"\ or not "K" or not "L" or not "M" or not "N" or not "O" or not "P" or not "Q" or not "R" or not "S" or not "T"\ or not "U" or not "V" or not...

  • ##8. A program contains the following function definition: ##def cube(num): ##return num * num * num...

    ##8. A program contains the following function definition: ##def cube(num): ##return num * num * num ##Write a statement that passes the value 4 to this function and assigns its return value ##to the variable result. ##9. Write a function named times_ten that accepts a number as an argument. When the ##function is called, it should return the value of its argument multiplied times 10. ##10. Write a function named is_valid_length that accepts a string and an integer as ##arguments....

  • For my computer class I have to create a program that deals with making and searching...

    For my computer class I have to create a program that deals with making and searching tweets. I am done with the program but keep getting the error below when I try the first option in the shell. Can someone please explain this error and show me how to fix it in my code below? Thanks! twitter.py - C:/Users/Owner/AppData/Local/Programs/Python/Python38/twitter.py (3.8.3) File Edit Format Run Options Window Help import pickle as pk from Tweet import Tweet import os def show menu():...

  • The code: def isPalindrome(text): """ >>> isPalindrome("alula") True...

    The code: def isPalindrome(text): """ >>> isPalindrome("alula") True >>> isPalindrome("love") False >>> isPalindrome("Madam") True >>> isPalindrome(12.5) False >>> isPalindrome(12.21) False >>> isPalindrome("Cigar? Toss it in a can.! It is so tragic.") True >>> isPalindrome("travel.. a town in Alaska") False """ # --- YOU CODE STARTS HERE if type(text) is not str: return False l = len(text) - 1 i = 0 while i < l: if text[i] in string.punctuation or text[i] == ' ': i += 1 elif text[l] in...

  • Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is...

    Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is the index of a word in the text that matches your given # search string. # e.g. if "hatter" occurs at positions 0, 6, 12 then return [ 0, 6, 12] def search_linear_occurrences(xs, target): """ Find and return a list of...

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