Problem 1. Write a Python function times_i_at_odd(L) that takes
as arguments a
list L and returns a list consisting of the elements of L
multiplied by the index number of the element at odd positions.
(Use list comprehensions)
>>> times_i_at_odd([1,2,3,4,5,6,7,8,9,10]) [2, 12, 30, 56, 90]
Problem 2. Write a recursive function sum_cols(grid, n) that takes a list of lists of integers grid and integer n and returns the sum of column n in grid. For example, the call
sum_cols([[1,2,3,4], [10,20,30,40], [100,200,300,400]], 2) should return 333.
Problem 3. Write a recursive function replace(s, a, b) that takes as arguments the strings s, a, and b and replaces all the occurrences of string a with string b in string s.
a) For your solution, assume that string a is only one character long.
b) For your solution, assume that string a can be of any size. Use s.startswith(a), which returns True if string s starts with a and False otherwise.
Thanks for the question.
Here is the completed code for this problem. Let me know if you have any doubts or if you need anything to change.
Thank You !!
================================================================================================
def times_i_at_odd(num_list):
return [num_list[i]*num_list[i+1] for i in range(0,len(num_list),2)]
print(times_i_at_odd([1,2,3,4,5,6,7,8,9,10]))
def sum_cols(grid,n):
if len(grid)==1:
return grid[0][n]
else:
return grid[0][n]+sum_cols(grid[1:],n)
print(sum_cols([[1,2,3,4], [10,20,30,40], [100,200,300,400]], 2) )
def replace(s,a,b):
if len(s)==1:
if s==a:return b
else:return s
else:
if s[0]==a:return b+replace(s[1:],a,b)
else:return s[0]+replace(s[1:],a,b)
print(replace('elephant','e','<e>'))

Problem 1. Write a Python function times_i_at_odd(L) that takes as arguments a list L and returns...
Write a decorator function in python that takes in 3 strings as arguments and returns them in reverse order.
Python 3.0 Please Write a function that takes, as arguments, a binary string, a list of characters and the corresponding Huffman code for those characters. It decodes the binary string using the Huffman code, and returns the resulting decoded string. Name this function decodeStringHuffman(binaryString, myCharacters, myCode). For example, >>>decodeStringHuffman("1001100010111010101010111", ["A", "B", "C"], ["1", "00", "01"]) should return the string 'ABAABCCAACCCCCAA'
Python Write a function square(a) that takes a list a of numbers and squares each of the numbers in the list. The function should not return a value (more specifically, it should return None). Write a function squared(a) that takes a list a of numbers and returns a new list that contains each value in a squared. The original list a should not be modified by your function. Write a function lowercase(a) that takes a list a of strings and...
With using Python . Write a function that: 1. Takes two arguments and returns the product of the arguments. The return value should be of type integer. 2. Takes two arguments and returns the quotient of the arguments. The return value should be of type float. 3. Takes one argument and squares the argument. It then uses the two values and returns the product of the two arguments.(Reuse function in 1.) 4. Takes one argument and prints the argument. Use...
Write a function called most_consonants(words) that takes a list of strings called words and returns the string in the list with the most consonants (i.e., the most letters that are not vowels). You may assume that the strings only contain lowercase letters. For example: >>> most_consonants(['python', 'is', 'such', 'fun']) result: 'python' >>> most_consonants(['oooooooh', 'i', 'see', 'now']) result: 'now' The function that you write must use a helper function (either the num_vowels function from lecture, or a similar function that you...
PYTHON The function longest that returns the longest of two strings. The function count_over that takes a list of numbers and an integer nand returns the count of the numbers that are over n. The function bmi that takes two parameters height and weight and returns the value of the body mass index: a person's weight in kg divided by the square of their height in meters. def longest(string1, string2): """Return the longest string from the two arguments, if the...
Write a function findEvens that takes an integer, n, as input and returns the list of even integers between 1 and n. Ex. Input: 10 Output: [2,4,6,8,10] Write a function sortList that takes in a list of strings and returns a list of those strings now sorted and lowercase. Ex. Input: [‘ABE’,’CAD’,’gaB’] Output: [‘abe’,’acd’,’abg’] Both done in Python
Python Write a function list_copy(l) that takes a list as a parameter and returns a copy of the list using a list comprehension. please provide unittest
Write a function rm_multiple() that takes two parameters as input (a list of strings, and a list of strings to remove from the list) and returns a new list with the items removed. # Define function in this cell def rm_multiple(strings,remove_list): l = [10,20,40,50] #use to delete an element in the list for string in strings: strings= l if string not in remove_list: lst.append(string) # Edit the code here to call your function in this cell items = [10,20,40,50] to_remove...
1. Question: Write a function that takes a list L and returns a random sublist of size N of that list. Assume that the indexes must be in increasing order. That is, you cannot go backwards Example L [1, 2, 3, 4, 5] 5 The function should return one of these lists: [2, 3, 4] [2, 3, 5] [2, 4, 5] [3, 4, 5]