Question

In: Computer Science

no dictionaries please Returns a new string which is lowercase version of the given word with...

no dictionaries please


Returns a new string which is lowercase version of the given word
with special characters and digits removed

The returned word should not have any of the following characters:
! . ? : , ' " - _ \ ( ) [ ] { } % 0 1 2 3 4 5 6 7 8 9 tab character and new-line character

>>> clean_word("co-operate.")
'cooperate'
>>> clean_word("Anti-viral drug remdesivir has little to no effect on Covid patients' chances of survival, a study from the World Health Organization (WHO) has found.")
'antiviral drug remdesivir has little to no effect on covid patients chances of survival a study from the world health organization who has found'
>>> clean_word("1982")
''
>>> clean_word("born_y1982_m08\n")
'bornym'

Solutions

Expert Solution

Here is the function, no dictionary were used


================================================================

def clean_word(sentence):
    cleaned_word = ''
    filtered = '!.?:,\'"-_\()[]{}%0123456789'
    for letter in sentence:
        if letter not in filtered:
            cleaned_word += letter
    return cleaned_word.lower()


def main():
    print(clean_word("co-operate."))
    print(clean_word(
        "Anti-viral drug remdesivir has little to no effect on Covid patients' chances of survival, a study from the World Health Organization (WHO) has found."))
    print(clean_word('1982'))
    print(clean_word("born_y1982_m08\n"))


main()

==================================================================


Related Solutions

You will be given a string, containing both uppercase and lowercase alphabets(numbers are not allowed). You...
You will be given a string, containing both uppercase and lowercase alphabets(numbers are not allowed). You have to print all permutations of string with the added constraint that you can’t change the uppercase alphabets positions. Respond in Python please
####################################################################### ##################################### ###############python################# # RQ1 def merge(dict1, dict2): """Merges two Dictionaries. Returns a new dictionary that...
####################################################################### ##################################### ###############python################# # RQ1 def merge(dict1, dict2): """Merges two Dictionaries. Returns a new dictionary that combines both. You may assume all keys are unique. >>> new = merge({1: 'one', 3:'three', 5:'five'}, {2: 'two', 4: 'four'}) >>> new == {1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five'} True """ "*** YOUR CODE HERE ***" # RQ2 def counter(message): """ Returns a dictionary where the keys are the words in the message, and each key is mapped (has associated...
For python Write a new method for the Fraction class called mixed() which returns a string...
For python Write a new method for the Fraction class called mixed() which returns a string that writes out the Fraction in mixed number form. Here are some examples: f1 = Fraction(1, 2) print(f1.mixed()) # should print "1/2" f2 = Fraction(3, 2) print(f2.mixed()) # should return "1 and 1/2" f3 = Fraction(5, 1) print(f3.mixed()) # should return "5" def gcd(m, n): while m % n != 0: oldm = m oldn = n m = oldn n = oldm %...
Create a method that returns the third character from the String word. Be sure to use...
Create a method that returns the third character from the String word. Be sure to use a try catch block and use the appropriate exception to deal with indexes out of a String’s bound: StringIndexOutOfBoundsException. Return the character 'x' (lowercase) when this exception is caught. Do not use if statements and do not use the general exception handler Exception. Examples: thirdLetter("test") -> 's' public char thirdLetter(String word) { } ​should return the char 'r'
a) Given a variable word that has been assigned a string value,write a string expression...
a) Given a variable word that has been assigned a string value, write a string expression that parenthesizes the value of word. So, if word contains "sadly", the value of the expression would be the string "(sadly)"b) Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Write a statement that prints the value of price in the form "X dollars and Y cents" on a line by itself. So,...
Given a string, write a method called removeRepthat returns another string where adjacent characters that are...
Given a string, write a method called removeRepthat returns another string where adjacent characters that are the same have been reduced to a single character. Test the program by calling the method from the main method. For example: removeRep(“yyzzza”) à “yza” removeRep(“aabbbccd”) à “abcd” removeRep(“122333”) à “123”
Write a function checkvertical(board, word, row, col), which returns True if the word word can be...
Write a function checkvertical(board, word, row, col), which returns True if the word word can be added to the board starting at position board[row][col] and going down. The restrictions are (1) it has to fit entirely on the board, (2) it has to intersect and match with one or more non-blank letters on the board, and (3) it cannot change any letters on the board, other than blanks (that is, overlapping mismatches are not allowed). My program isn't working :(...
public static java.lang.String removerec(java.lang.String s) Returns a string similar to the given string with all runs...
public static java.lang.String removerec(java.lang.String s) Returns a string similar to the given string with all runs of consecutive, repeated characters removed. For example, given "apple", returns "aple" given "banana", returns "banana" given "baaannannnnaa", returns "banana" given an empty string, returns an empty string Parameters: s - given string Returns: string created from s by removing runs of the same character
python 3 please Define a function voweliest that takes as input a string and returns as...
python 3 please Define a function voweliest that takes as input a string and returns as output a tuple where the string that has the most vowels in it is the first element and the second is the number of vowels in that string. Note: don't worry about ties or capital letters Hint: consider defining and using a separate function that counts the number of vowels in a given string
Define an interface called Vehicle, which requires the following methods getName: returns a String getTopSpeed: returns...
Define an interface called Vehicle, which requires the following methods getName: returns a String getTopSpeed: returns an int getMaxPassengers: returns an int Note that the class Car implements this interface and is preloaded (in one of the following questions you will define this class) For example: Test Vehicle v = new Car("BMW", 280, 5); System.out.println(v.getName()); System.out.println(v.getTopSpeed()); System.out.println(v.getMaxPassengers()); Results : BMW 280 5 Test 2 : Vehicle v = new Car("Smart", 150, 2); System.out.println(v.getName()); System.out.println(v.getTopSpeed()); System.out.println(v.getMaxPassengers()); Results : Smart 150 2
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT