Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with strings (name it listst) and the second parameter is a single string (name it st). The function should return a number, indicating how many of the strings in the list listst are substrings in the string st
As an example, the following code fragment:
listst = ["a","bc","dd"] st = "abc"
res = how_many_substr_of_string(listst,st) print (res)
should produce the output:
2
Language Python
def how_many_substr_of_string(listst,st):
# using list comprehension
# to get string with substring
return len([i for i in listst if i in st])
listst = ['ab', 'abc', 'efg', 'bc']
st = 'abcde'
result=how_many_substr_of_string(listst, st)
print(result)
Output:
3
Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with...
Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with strings (name it listst) and the second parameter is a single string (name it st). The function should return a number, indicating how many of the strings in the list listst are substrings in the string st As an example, the following code fragment: listst = ["a","bc","dd"] st = "abc" res = how_many_substr_of_string(listst,st) print (res) should produce the output: 2 language:Python
Define a function named double_add_digits_in_string(...) which receives a string as a parameter and returns the sum of the digits multiplied by two. A solution using a loop is expected. As an example, the following code fragment: total = double_add_digits_in_string("xx1xx2xx3xx") print (total) should produce the output: 12
Create a function named list_numbers_in_words(...) which receives as a parameter a positive integer number and returns a list with the words corresponding to each digit, in the same order as the digits appear in the number. As an example, the following code fragment: res = list_numbers_in_words(5438) print(res) should produce the output: ['five', 'four', 'three', 'eight']
Define a function add_nums_x_pos_given_list_nums (..) which receives a list that is guaranteed to only have numbers (or the empty list) and returns the sum of each number multiplied by the position where the number is. (In the case of the empty list the function it will return 0) For example add_nums_x_pos_given_list_nums ([10,20,30]) will return the value 80 which is the result of adding: 0 * 10 (10 is in position 0 in the list) + 1 * 20 + 2...
Define a function named food which receives two parameters: an integer value representing the time of the day measured in hours from 0 to 24 and a Boolean value indicating whether a person likes sweets (True) or not (False). The function should return one single string with a message as follows. If it is earlier than 6, the message should say "no food" (regardless of the person liking sweets or not). If it is between 6 and 10 extremes included,...
PYTHON define a function called fav_colours(): which receives a list of strings of lowercasecolours: the list some words will repeat, one colour or many, long list or short, Will always be lowercase - return a list of lists containing unique colours and integer numbers describing the amount of times those colours repeated As an example, the following code fragment: colours = ['blue', 'red', 'red', 'red', 'green'] colours , numbers = fav_colours(colours) print(colours) print(numbers) should produce the output: ['blue', 'red', 'green']...
Define a function funD2(...) which receives a list lst that contains single letters, single digits and single special characters (and the list contains at least one element of each type). The function returns a string that contains the last letter and the last special character of the list, where each is repeated as many times as the sum of all digits in the list. As an example, the following code fragment: lst = ["a","b","c", 1, 2, "$","%"] print (funD2(lst)) should...
PYTHON Define a function reverseNestedList(...) which receives one possibly nested list (lst1) and returns the reverse of both the given list and any nested lists inside it. Note that the testing inputs will not include lists that are nested more than twice (a list in a list in a list ++...) [[[...],1], 1] Good luck! As an example, the following code fragment: lst1 = [[1, 2], [3, 4]] print(reverseNestedList(lst1)) should produce the output: [[4, 3], [2, 1]]
D.1 [3] Define a function called funD1...) that receives a string and returns a new string with all the characters in the original string in an EVEN position. As an example, the following code fragment: print (funD1('abcde')) should produce the output: ace D.2 [6] Define a function funD2(...) which receives a list ist that contains single letters, single digits and single special characters and the list contains at least one element of each type). The function returns a string that...
language is python Write a function named subsetStrings that has two inputs, a list of strings and an integer n. Your function should use a single list comprehension to create a new list containing the first n characters of each string in the input list if the length of the individual string is at least n (strings that are too short should be skipped). Your function should return the new list ex: inputList 'Frederic, 'powerade', 'spring break, 'pen'] and n-4...