Using Python 3.6.4:
10.34 Using linear recursion, implement function recDup() that takes a list as input and returns a copy of it in which every list item has been duplicated.
>>> recDup(['ant', 'bat', 'cat', 'dog'])
['ant', 'ant', 'bat', 'bat', 'cat', 'cat', 'dog', 'dog']
def recDup(lst):
if len(lst)==0:
return []
else:
return [lst[0],lst[0]]+recDup(lst[1:])
# Testing
print(recDup(['ant', 'bat', 'cat', 'dog']))


Using Python 3.6.4: 10.34 Using linear recursion, implement function recDup() that takes a list as input...
Solve in Python 3: Implement function four_letter() that takes as input a list of words (i.e., strings) and returns the sublist of all four letter words in the list. >>> four_letter(['dog', 'letter', 'stop', 'door', 'bus', 'dust']) ['stop', 'door', 'dust']
write a function firstLetterWords(words) that takes as a parameter a list of strings named words and returns a dictionary with lower case letters as keys. But now associate with each key the list of the words in words that begin with that letter. For example, if the list is ['ant', 'bee', 'armadillo', 'dog', 'cat'], then your function should return the dictionary {'a': ['ant', 'armadillo'], 'b': ['bee'], 'c': ['cat'], 'd': ['dog']}.
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
Define a Python function that takes a list and returns the length of the list using map and sum.
Need help on question No.5
In python
Must use recursion
Must use recursion
Must use recursion
Thank you
LinkedList
MISU (Annoyed that this means you don't have much flexibility about how to implement this function? I apologizel But I don't regret it - I think that these debug printouts will help most students.) 5 accordion(old head) This function takes an old list, removes every other node, and then returns the updated list. Old nodes, which are removed from the list,...
(Python)Implement the function deep_list, which takes in a list, and returns a new list which contains only elements of the original list that are also lists. Use a list comprehension. def deep_list(seq): "" "Returns a new list containing elements of the original list that are lists. >>> seq = [49, 8, 2, 1, 102] >>> deep_list(seq) [] >>> seq = [[500], [30, 25, 24], 8, [0]] >>> deep_list(seq) [[500], [30, 25, 24], [0]] >>> seq = ["hello", [12, [25], 24],...
Python: P2 Write a function that reverses a python list using recursion (Chapter 6-3 in our textbook) E.g.: Input: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Constraints: - List elements are integers - The function should return a reversed array, not print its elements You may use the following code as template: def reverse(my_list, index = None): # your code here
Python: Write a function subsetSum() that takes as input a list of positive number and a positive number target. The function returns True if there are three numbers in the list that add up to the target. For example, the list [5, 4, 10, 20, 15, 19] and targert 38, then True is returned since 4 + 15 + 19 = 38. However, the list [5, 4, 10, 20, 15, 19] and target 5 returns False. >>> subsetSum([5, 4, 10,...
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
In python: FindWordCount is a function that takes in a list and a string. The function then returns the number of occurances of the string in the list. Here's an example of using this function: >>> a = LoadFile("alice.txt") >>> PrintOutput(str(FindWordCount(a, "Alice"))) OUTPUT 403