'''Assignment 1.Author:'''import math# Maximum number of characters in a valid tweet.MAX_TWEET_LENGTH = 50# The first character in a hashtag.HASHTAG_SYMBOL = '#'# The first character in a mention.MENTION_SYMBOL = '@'# Underscore is the only non-alphanumeric character that can be part# of a word (or username) in a tweet.UNDERSCORE = '_'SPACE = ' 'def is_valid_tweet(tweet: str) -> bool:"""Return Tru
...[Show More]
'''Assignment 1.
Author:
'''
import math
# Maximum number of characters in a valid tweet.
MAX_TWEET_LENGTH = 50
# The first character in a hashtag.
HASHTAG_SYMBOL = '#'
# The first character in a mention.
MENTION_SYMBOL = '@'
# Underscore is the only non-alphanumeric character that can be part
# of a word (or username) in a tweet.
UNDERSCORE = '_'
SPACE = ' '
def is_valid_tweet(tweet: str) -> bool:
"""
Return True if and only if tweet contains between 1 and
MAX_TWEET_LENGTH characters (inclusive).
>>> is_valid_tweet('Hello Twitter!')
True
>>> is_valid_tweet(' ')
False
>>> is_valid_tweet(2 * 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
False
"""
for x in tweet:
if (x != ' ') and len(tweet) <= MAX_TWEET_LENGTH:
return True
return False
def compare_tweet_lengths(tweet1: str, tweet2: str) -> int:
"""
returns int(1) if the first tweet is longer than the second, returns
int(-1) if the second is longer than the first, and returns int(0)
if the tweets have the same length.
Precondition: both tweets must be valid
>>> compare_tweet_lengths('abc', 'abcd')
-1
>>> compare_tweet_lengths('abcde', 'abcd')
1
>>> compare_tweet_lengths('abcde', 'abcde')
0
"""
if len(tweet1) > len(tweet2):
return 1
elif len(tweet1) < len(tweet2):
return -1
return 0
def add_hashtag(tweet: str, word: str) -> str:
""" Returns tweet + " " + # + word if tweet is a valid
[Show Less]