Question: In python 1) Write a recursive function pattern that displays number sequence patterns as defined below: pattern (0)displays0 pattern (1)displays 0 1 0 pattern (2)displays

In python

1)

Write a recursive function pattern that displays number sequence patterns as defined below:

pattern (0)displays0

pattern (1)displays 0 1 0

pattern (2)displays 0 1 0 2 0 1 0

pattern (n) displays pattern(n-1) n pattern (n-1)

test for pattern (0), pattern(1), pattern(2), pattern(3) and pattern(4).

2)

Write a gsort function takes two parameters: a comparison function and a list of values, then sort the list according to the comparison function provided. For each of the following case, write its corresponding comparison function and call the gsort function to perform the task. Do not use any predefined sorting function such as sort or sorted. (note: using lambda function is fine but optional.)

Sort the integer list [5, 2, 12, 4, 9, 13, 22, 1, 6, 17] to descending order.

Sort the name list [Kate, Sam, Kate, Jolly, Alp, Beta, Alpine, Samuel, Bob, Joy] according to alphabetical order.

Sort the tuple list of (name, count) according to names alphabetical order. If same name, then the one has higher count listed first. [(Kate, 3), (Sam, 2), (Kate, 5), (Jolly, 1), (Alp, 2), (Beta, 3), (Alp, 1), (Alpine, 2), (Sam, 4), (Bob, 2), (Sam, 3)].

3)

Generate a list L of size 20 with random integer values from 1 to 100, then use map and/or filter functions to perform the following:

Produce a new list with each element is a doubled value of corresponding element in L. For example, if a list is [3, 12, 6, 7] the result list is [6, 24, 12, 14]

Produce a list with each element a squared value of each odd element in L. For example, if a list is [3, 2, 6, 7] the result list is [9,49]

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!