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.
'''
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.
"""
with open(filename) as f:
for line in f:
if line.startswith(title):
return True
return False
def contains_song(title: str, filename: str) -> bool: ''' Return True iff title (the name of a...
COMPLETE THE FOLLOWING QUESTION def find_favourite_artist(filename: str) -> str: ''' Return the name of the artist that occurs most frequently in the song file of the given filename. If there are more than one artists that occur most frequently, just return any of them. Note: Feel free to create helper functions for this if you need to. Hint: You may want to use the "sorted" function. ''' pass THE SONG FILE IS: Title, Singer, Release Year Let it go, Idina...
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...
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)
Write a function that takes, as an argument, the name of a file, fileName . Your program should open (and read through) the file specified, and return the maximum value in the file. Name this function maxValueInFile(fileName). def openFile(): # Prompt for the file name filename =input("Enter a file name: " ) # Open the file for reading file = open(filename) # Prompt for the target value target =input("Enter a threshold value: ") # Initialize the counter counter = 0...
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...
Implement and test the following function://bool ispalindrome(string s)//return true iff s is a palindrome//For example: ispalindrome("RADAR") return true, //ispalindrome("ABCD") returns false. Enter word to find if the word is palindrome: RADAR The word is RADAR a palindrome Press any key to continue .. Enter word to find if the word is palindrome: ABCDEF The word is ABCDEF is not a palindrome Press any key to continue......
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
12. (10 pts) Fill in the blanks according to the documentation: def readAndStrip (fileName, charsToRemove) : ""This function will take in a fileName and characters to remove. It will read everything from the fileName and return a lis of all the words with given chars ToRemove removed.""" #Open the file file = #Read the file #Close the file #Create the list #Strip all the charsToRemove for #return the clean list return
def most_expensive_item(price_list: List[list]) -> str: """Return the name of the most expensive item in price_list. Precondition: price_list is a list of lists in the following format: [ [str, int], [str, int], ... ] where each 2-element list represents a name (str) and a price (int) of an item. price_list has at least one element. >>> price_list = [["apple", 1], ["sugar", 5], ["mango", 3], ... ["coffee", 9], ["trail mix", 6]] >>> most_expensive_item(price_list) """ please complete the function body in Python
In Python
4. outputWordPointPairs(pointWordList, filename, toFile) NO return (just prints a formatted list or writes it to file). NOTE: Your function should add the .txt extension to the filename before opening a file with that name. Write a function which will output the (pointValue, word) pairs in pointWordList to the shell or to a file depending on the bool value toFile. Note the order of elements of the tuple is (pointValue, word) not (word, pointValue). Find out why this specific...