Question: PYTHON. In this assignment, you will implement some functions related to strings, lists, sets and tuples. Each function has been defined for you, but without

PYTHON. In this assignment, you will implement some functions related to strings, lists, sets and tuples. Each function has been defined for you, but without the code. See the docstring in each function for instructions on what the function is supposed to do and how to write the code. It should be clear enough. In some cases, we have provided hints to help you get started.

please answer 1-7thank you

1. def concatenate(strings): Concatenates the given list of strings into a single string. Returns the single string. If the given list is empty, returns an empty string.

lst = ["a","b","c"] assert_equal("abc",concatenate(lst)) lst = [] assert_equal("",concatenate(lst))

2. def all_but_last(seq): """ Returns a new list containing all but the last element in the given list. If the list is empty, returns None.

lst = [] assert_equal(None,all_but_last(lst)) lst = [1,2,3,4,5] nose.tools.assert_list_equal([1,2,3,4],all_but_last(lst)) lst = ["a","d",1,3,4,None] nose.tools.assert_list_equal(["a","d",1,3,4],all_but_last(lst))

3.def remove_duplicates(lst): """ Returns the given list without duplicates. The order of the returned list doesn't matter.

4. def reverse_word(word): """ Reverses the order of the characters in the given word.

word = "abcdefg" assert_equal("gfedcba",reverse_word(word))

word = "a b c d e f g" assert_equal("g f e d c b a",reverse_word(word))

word = "a b" assert_equal("b a",reverse_word(word))

word = "" assert_equal("",reverse_word(word))

5.def divisors(n): """ Returns a list with all divisors of the given number n. As a reminder, a divisor is a number that evenly divides another number. The returned list should include 1 and the given number n itself. The order of the returned list doesn't matter.

number = 10 nose.tools.assert_count_equal([1,2,5,10],divisors(number))

number = 1 nose.tools.assert_count_equal([1],divisors(number))

number = 7 nose.tools.assert_count_equal([1,7],divisors(number))

6.def capitalize_or_join_words(sentence): """ If the given sentence starts with *, capitalizes the first and last letters of each word in the sentence, and returns the sentence without *. Else, joins all the words in the given sentence, separating them with a comma, and returns the result.

string = "*i love python" assert_equal("I LovE PythoN",capitalize_or_join_words(string))

string = "i love python" assert_equal("i,love,python",capitalize_or_join_words(string))

string = "i love python " assert_equal("i,love,python",capitalize_or_join_words(string))

7. def move_zero(lst): """ Given a list of integers, moves all non-zero numbers to the beginning of the list and moves all zeros to the end of the list. This function returns nothing and changes the given list itself.

lst = [0,1,0,2,0,3,0,4] assert_equal(None,move_zero(lst)) nose.tools.assert_list_equal([1,2,3,4,0,0,0,0],lst)

lst = [] move_zero(lst) nose.tools.assert_list_equal([],lst)

lst = [0,0,0,0,0,0,0,0,0] move_zero(lst) nose.tools.assert_list_equal([0,0,0,0,0,0,0,0,0],lst)

lst = [1,2,3,4,5,6,7,8] move_zero(lst) nose.tools.assert_list_equal([1,2,3,4,5,6,7,8],lst)

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!