Question: WRITE A FUNCTION FOR EACH OF THE FOLLOWING TASKS ( 1 0 0 Pts ) ( a ) ( 1 0 Pts ) [ Task

WRITE A FUNCTION FOR EACH OF THE FOLLOWING TASKS (100 Pts)(a)(10 Pts)[Task-1] Define a function called repeat letters that takes a string and a number n as two parameters and prints the string with every letter repeated n times.Sample input/Output: print(repeat letters(medipol,3)) mmmeeedddiiipppooolll(b)(10 Pts)[Task-2] Define a function called find index which takes as argument a word and a letter. It will return the index of the second occurrence of the letter in the given word.Sample input/Output: print(find index(welcomehome, e))6(c)(10 Pts)[Task-3] Define a function called list unique that takes a string str as an input, checks all letters of the string, and constructs a list that contains the list of character that appear in str. This list should not contain any duplicates.Sample input/Output: print(list unique(ankara))[a, n, k, r](d)(10 Pts)[Task-4] Write a function called ngrams list that takes a string and a number n and return the n-grams of the this string as a listSample input/Output: print(ngrams list(computer,2))[co,om,mp,pu,ut,te,er]2(e)(10 Pts)[Task-5] Imagine a dictionary with the structure student id:[student major, student cgpa]. Assume majors are represented by strings like CoE, EEE, etc. Now define a function avg cgpa by major that takes such a dictionary and a string for major as inputs and returns the average cgpa for all students with that major.Sample input/Output: In 1={41251:[CoE,2.5],42509:[EEE,3.1],41713:[CoE,1.9],41101:[CoE,2.7]} print(avg cgpa by major(In 1,CoE))2.36(f)(10 Pts)[Task-6] Define a function called search dict which will take a dictionary and a number as arguments. It will search through dictionarys values, and return True if that number appears in the dictionary as an integer or as a stringSample input/Output: d1={ Ahmet: 10, Zeynep: 5, Mehmet: 2} print(search dict(d1,5))(g)(10 Pts)[Task-7] Define a function called hist A, it takes a string input and finds which letter exists how many times in this given string.Sample input/Output: print(hist A(kara murat kim)){k:2, a:3, r:2, m:2, u:1, i:1, :2}3(h)(10 Pts)[Task-8] Define a function called hist B which takes the Output dictionary (given by hist A [Task-7]) as an input. And create a new dictionary which maps from frequencies to letters.Sample input/Output: res = hist A(kara murat kim)) print(hist B(res)){1: [u, t, i],2: [, r, k, m],3: [a]}(i)(10 Pts)[Task-9] Define a function called getTopelements that takes a string as an input and returns the most common 3 letters in that string. If the characters have same frequency, it should return in alfabetical order.Sample input/Output: print(getTopelements(programming)) Most common three letters are: m, a, g(j)(10 Pts)[Task-10] Define a function called compress dict, it compresses the strings that have long sequences of equal characters. The program will accept one string as an argument, and return compressed form of the string.Sample input/Output: print(compress dict(aaaabbaaabbbbbbcccd))4a2b3a5b3c1d 4

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 Programming Questions!