Ask Question
25 May, 22:50

Write a function named "list_concat" that takes a list of strings as a parameter and returns the concatenation of all the values in the list as a single string with each value separated by a space. For example, if the input is ["limit", "break", "ready"] the output should be "limit break ready"

+5
Answers (1)
  1. 26 May, 02:48
    0
    Following are the program in python language:

    def list_concat (ls) : #define function

    if (len (ls) = = 0) : #set if condition

    return ""

    res = ""

    for x in ls: #set for loop

    res + = x + " "

    return res[:len (res) - 1] #removing the extra spaces from list

    ls = ['limit','break','ready'] #initialize the value in list

    print (list_concat (ls)) #call the function

    Output:

    limit break ready

    Explanation:

    Here we declared a function "list_concat () " in which we pass an argument "ls" then check if condition that check the length of list. We also Iterating the loop in that function res[:len (res) - 1] statement removes the extra space from the list and finally print the list
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a function named "list_concat" that takes a list of strings as a parameter and returns the concatenation of all the values in the ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers