Question: Need help with finishing these functions by Python code and the code should be satisfied with these tests import unittest import re def string_splitting (

Need help with finishing these functions by Python code

Need help with finishing these functions by Python code and the codeshould be satisfied with these tests import unittest import re def string_splitting( input_str, delim.): Split the given.string, using the delimiter passed as aparamater. ...Ex. -code-block::python ... >>> string_splitting ("Under.the.Mirabeau flows the. Seine. And ouramours",:'.') ....... ['Under', 'the', 'Mirabeau','flows', 'the', 'Seine', "And','our', . 'amours'] ... Topics:'split() method ...param input_str: the string to be splitted ..:type input_str: str:param delim: delimiter ...:type delim: str :return: an array of string tokensurtype: list pass def matches (input_str, regexp): Return a list of all.substringsthat match the given regexp. Ex. code-block::python >>> matches ("abc\tdelfabcde12fabc\t345def", r' (abc\t]\d{2}}')

and the code should be satisfied with these tests

['abc\t', '12', 'abc\t','34'] Topics: re.findall() method TT TT 11 pass Idef filter

import unittest import re def string_splitting ( input_str, delim.): Split the given.string, using the delimiter passed as a paramater. ...Ex. -code-block::python ... >>> string_splitting ("Under.the.Mirabeau flows the. Seine. And our amours",:'.') ....... ['Under', 'the', 'Mirabeau','flows', 'the', 'Seine', "And','our', . 'amours'] ... Topics: 'split() method ...param input_str: the string to be splitted ..:type input_str: str :param delim: delimiter ...:type delim: str :return: an array of string tokens urtype: list pass def matches (input_str, regexp): Return a list of all.substrings that match the given regexp. Ex. code-block::python >>> matches ("abc\tdelfabcde12fabc\t345def", r' (abc\t]\d{2}}') ['abc\t', '12', 'abc\t','34'] Topics: re.findall() method TT TT 11 pass Idef filter (.tpl ): Given a tuple. (immutable. list) of strings, return another list. where: ....*.words that have at least.10.letters are kept unchanged *. words that have less than 10 letters are replaced with the word length: (character.count) ...Ex.. code-block::python "parrott")) >>> filter ( ("lion", "hippopotamus", "kangaroo","tyrannosaurus", [4,'hippopotamus',:8,'tyrannosaurus', :7] ....... Topics: length of sequences and strings, if-else ternary expression, list comprehensions :param.tpl:.atuple of strings :type tpl: tuple :return: a list of strings :rtype: list pass def reverse_minus_last(.tpl ): .... Given a list of values, return.a. second list that meets the given criteria: ....*.it contains all elements of the first list, except the last one the order is reversed ....EX. code-block::python :>>>reverse_minus_last ((1,2,3,4,.5)) .. [4,3,2,1] .... Topics: ranges, subcripting sequences with positive and negative indexes, . 'reversed()' and 'list().functions ...param. tpl: tuple of integers. .:type.tpl: tuple ....:return: a list of integers. crtype: list pass def even_odd( tpl ): ...". Given.a. tuple of integers, return another.list. where even integers are replaced with a.0, and odd integers, ..with.a.1. - EX. code-block::python >>>. even_odd ((9,7,4,-3)) ...[1,1,0,1] .. Topics: list comprehensions :param.tpl: tuple of integers. ...:type.tpl: tuple :return: a list of Os.and. 1s. :rtype: list pass def differences (.tpl.): . """.Given a tuple of integers of size. :math: 'n , return a list where each of the math: 'n-1'.. elements is the diffence between two consecutive elements of the first.list. Ex. code-block:: python >>> differences ((9,7, 4,:3)) ... [2,3,1] Topics: list. comprehensions ...param. tpl: tuple of integers. ..:type.tpl: tuple return: a list of integers crtype: list pass def string_from_different types ( inputi, input2 ): ...Given two inputs of different types. (say: a string and an integer, or an integer and a float, ...), .... construct and return a string that concatenate the two values in a single string. ...EX. code-block:: python :>>>.string_from_different_types (-5,2.3.) "52.31 Topics: 'str. formato function. param input1: any value :type input1: object :param. input2: any value ...:type input2: object :return: a string of the form.' ....:rtype: str pass def string_from_list( input_list ): IT IT! ...Given a list of arbitrary length made of different types. (e.g.a. string, an integer, and a float), .... construct and return a string that concatenate all values in a single string. Ex. code-block::python :>>> string_from_list(-5,2.3,' zebras', type (7.2) :) "52.3zebras" Topics: 'str().and. 'str.join() functions, list.comprehension. :param input1: any value ....:type.input1: object ...::param input2: any value ...:type input2: object ...return: a string of the form.' ..:rtype: str pass def check_for_keys ( dictionary, keys ): 1 1 1 1 ...Given a dictionary. (aka..hash table) and a tuple of keys, return a list of same. length, where each .... key is replaced with.l.if it matches an existing.entry in the dictionary, or a.o.otherwise. Ex. code-block::python P... >>>check_for_keys ( {"I":1,"am":2,"not":3,"there":5},['not','owl', 'am', 'blue'] :) .....[1,0, 1, 0] .... Topics: list comprehensions, dictionaries, ternary conditional expressions :param dictionary: a dictionary structure ...:type dictionary: dict Priparam keys:.a. tuple of objects :type keys: tuple :return: a list of integers :rtype: list pass class Testclass ( unittest. Test Case): def test_string_splitting (self): self.assertEqual( string_splitting ( "Under.the.Mirabeau flows the. Seine. And our amours", ') ...........['Under', 'the', 'Mirabeau', 'flows', 'the', 'Seine', 'And', 'our', 'amours'] def test matches (self): self.assertEqual ( matches ( "abc\tdelfabcde12fabc\t345def", r' (abc\t]\d{2}}'), .........['abc\t', '12', 'abclt','34']) def test filter (self): self.assertEqual ( filter( ("lion", "hippopotamus", "kangaroo","tyrannosaurus", "parrott")), .... [4, 'hippopotamus',8,'tyrannosaurus', 7]) def test_reverse_minus_last (self): self. assertEqual( reverse_minus_last ((5,4,3,2,1,0)),[1,2,3,4,5]) def test_even_odd (self): self.assertEqual ( even_odd ( (5,8,9,2, 13, 25, 14)),[1,0,1, 0,1,1,0]) def test differences (self): self.assertEqual ( differences ( (9,7,4,3), [2,3,1]) def test_string_from_different types (self): self.assertEqual ( string_from_different_types (9.5, 'whales'), '9.5whales') 1 def test_string_from_list (self): self.assertEqual (string_from_list( [2.3, 'whales', 4]*4.), .......'2.3whales 42.3whales 42.3whales 42.3whales4') def test check for keys (self): dictionary = {"I": 1, "am": 2, "not": 3, "there":5} self.assertEqual ( check_for_keys ( dictionary, ['not', 'owl', 'am', 'blue']), [1,0,1,0])

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!