Question

Qhuestion 6 i.Write a recursive function reverseConcatenate that takes as input a list with string entries and returns one long string which is the concatenation of all the string entries in reverse o...

Qhuestion 6

i.Write a recursive function reverseConcatenate that takes as input a list with string entries and returns one long string which is the concatenation of all the string entries in reverse order. For instance, reverseConcatenate([’how’, ’are’, ’you?’]) should return ’you?arehow’.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer.)

Code: (Screenshot for proper indentation)

#define reverseConcatenate function def reverseConcatenate (1st): if len(1st) is 1: return 1st[-1] return 1st[-1] (reverseCon

#(Text version of the code from Student help)

#define reverseConcatenate function
def reverseConcatenate (lst):
if len(lst) is 1:
return lst[-1]
return lst[-1] + (reverseConcatenate (lst[:len(lst)-1]))

# Main Code
lst = ["how", "are", "you?"]
print("List is : ",lst)
print("Expected Output : ",reverseConcatenate (lst))

Output:

List is :  ['how', 'are', 'you?']                                                                                                                                                  

Expected Output :  you?arehow

Add a comment
Know the answer?
Add Answer to:
Qhuestion 6 i.Write a recursive function reverseConcatenate that takes as input a list with string entries and returns one long string which is the concatenation of all the string entries in reverse o...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a recursive function that takes a string as an input and returns the reverse of...

    Write a recursive function that takes a string as an input and returns the reverse of the string. Write a recursive function rec_string that produces the output shown below for the corresponding function calls. Write a main function to test the function. Method call rec_string(‘abcde’), will produce the following output: * e de cde bcde abcde Method call rec_string(‘abc’), will produce the following output: * c bc abc

  • C++ Write a recursive function that passes no parameters which returns the reverse of a global...

    C++ Write a recursive function that passes no parameters which returns the reverse of a global variable string str. It should be structured like this: string recursive() { return reversed_string; }

  • JAVA - Write a recursive function that takes a linked list as input and returns all...

    JAVA - Write a recursive function that takes a linked list as input and returns all of the elements in the linked list. Input: 1, 2, 3, 4, 5 Output: (1+2+3+4+5)/5 = 3 What I have: public static int findMean (Node head, Node cur, int n){ int average = 0; if (head == null){ if(n == 0) return 0; } if (n > 0){ int sum = n + findMean(head, head.next, n -1); average = (sum)/n; } return average; }...

  • Using C, Write a function reverse which takes a string as an argument, reverses the string...

    Using C, Write a function reverse which takes a string as an argument, reverses the string and returns the reversed string. Note; you should not return a string that you created inside the reverse function! For example: Test char str[]-"hello" printf("%s", reverse (str)); Result olleh

  • Language: Python Function name : findwaldo Parameters : string Returns: int Description: Write a recursive function...

    Language: Python Function name : findwaldo Parameters : string Returns: int Description: Write a recursive function that takes in a string containing some combination of letters, numbers, and spaces, and return the starting index of the first instance of “waldo” contained in that string. If the string does not contain “waldo”, return -1. This function IS case sensitive, so “waldo” is not the same as “WALDO”. Code using string functions such as .index() and .find() that oversimplify the problem will...

  • Write a recursive function that takes a string as input. This recursive function should open a...

    Write a recursive function that takes a string as input. This recursive function should open a file by the name of the string, and read the first word. Then attempt to open a file by the word you just read and repeat this process. This ends, when there is no file with the name you are looking for. At this point, cout the last word in the current file (the one where the first word was not a different file)....

  • Write a recursive function, take a String as input, return true, if the String is a...

    Write a recursive function, take a String as input, return true, if the String is a palindrome; false otherwise. For instance, if the input is: “A nut for a jar of tuna” Then the return value is true. Notice that the non English letters are ignored; the spaces are ignored; and it is NOT case sensitive. You must write recursive function. You shall turn in a complete program, including main function to use your function to test if a String...

  • C++ Write a recursive function that reverses the given input string. No loops allowed, only use...

    C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. #include <iostream> #include <string> using namespace std; //Write a recursive function 'void reverse(string &str)' that reverses the given input string. void reverse(string &str) { /*Code needed*/ } int main() {    string name = "sherry";    reverse(name);    cout << name << endl; //should...

  • Write the function deep_contains. It takes as input a number and a list. That list might...

    Write the function deep_contains. It takes as input a number and a list. That list might contain lists as elements, and those lists might contain lists, etc. The deep_contains' function should return a Boolean indicating whether the number is contained inputted list, or a sublist of it, or a sublist of that, and so forth. For example: deep_contains (3, (1,3,5]) returns True deep_contains(3, 11, [3,5]]) returns True deep_contains (3, 1, [[3,4],5),6]) returns True deep_contains (2, (1,3,5]) returns False This function...

  • Write a python function that takes a string as input, and returns a dictionary of frequencies...

    Write a python function that takes a string as input, and returns a dictionary of frequencies of all the characters in the string. For example: freq("dabcabcdbbcd") would return {"d":3, "a":2, "b":4, "c":3}. Then write a driver to demonstrate your function.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT