answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
VikaD [51]
1 year ago
13

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"
Computers and Technology
1 answer:
Marina CMI [18]1 year ago
7 0

Answer:

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

You might be interested in
Taylor and Rory are hosting a party. They sent out invitations, and each one collected responses into dictionaries, with names o
disa [49]

Answer:

Following are the code to this question:

def combine_guest(guest1, guest2):#defining a method combine_guest that accepts two dictionary

   guest2.update (guest1)#use dictionary guest2 that use update method to update guest2 dictionary

   return guest2#return guest2 dictionary values

Rory_guest= { "Ada":2, "Ben":3, "Dav":1, "Jo":3, "Charry":2, "Terry":1, "bob":4}#defining a dictionary and add value

Taylor_guest = { "Dav":4, "Nan":1, "bobert":2, "Ada":1, "Samantha":3, "Chr":5}#defining a dictionary and add value

print(combine_guest(Rory_guest,Taylor_guest))#calling the combine_guest method

Output:

{'Nan': 1, 'Samantha': 3, 'Ada': 2, 'bob': 4, 'Terry': 1, 'Jo': 3, 'Ben': 3, 'Dav': 1, 'Charry': 2, 'bobert': 2, 'Chr': 5}

Explanation:

In the code a method, "combine_guest" is defined, that accepts two dictionaries "guest1, guest2" inside the method, in which the "guest2" dictionary uses the update method to combine the value of the guest1 dictionary and use a return keyword to return guest2 values.

In the next step, two dictionaries are declared, that holds some values and use a print method to call the "combine_guest" method and prints its return values.  

7 0
1 year ago
Write a sequence of statements that create a file named "greeting" and write a single line consisting of "Hello, World!" to that
tia_tia [17]

Answer:

The solution code is written in Python 3 as below:

  1. outfile = open("greeting.txt", "w")
  2. outfile.write("Hello World")
  3. outfile.close()

Explanation:

To create a simple text file in Python, we can use Python built-in function, <em>open()</em>. There are two parameters needed for the open() function,

  1. the file name and
  2. a single keyword "w". "w" denote "write". This keyword will tell our program to create a file if the file doesn't exist.

The statement <em>open("greeting.txt", "w")</em> will create a text file named "<em>greeting.txt</em>" (Line 1)

To fill up the content in the greeting.txt, we use <em>write()</em> method. Just include the content string as the argument of the <em>write()</em> method. (Line 2)

At last, we use <em>close() </em>method to close the opened file,<em> outfile</em>. This will release the system resource from the<em> outfile.</em>

4 0
1 year ago
Choose the response that best completes the following statement.
lisabon 2012 [21]
I am guessing. My guess is code.
7 0
1 year ago
Read 2 more answers
BlockPy: #35.2) Animal Splits Write a function all_cats that consumes a comma-separated string of animals and prints whether all
maks197457 [2]

Answer:

def all_cats(data):

 dataArray = data.split(',')

 if(data==""):

   return True

 for i in dataArray:

   if('cat' not in i):

     return False

 

 return True

print(all_cats("gerbil,catfish,dog,cat"))

print(all_cats("cat,catfish"))

print(all_cats(""))

Explanation:

Step 1: define de function and the parameters

def all_cats(data):

Step 2: split the data by ,

dataArray = data.split(',')

Step 3 : validate if is an empty data and return true

if(data==""):

   return True

Step 4: Loop over de array data and validate if have cat in each data if not, then return false

for i in dataArray:

   if('cat' not in i):

     return False

Step 5 if have cat in each one return true

return True

Step 6 Validate with examples

print(all_cats("gerbil,catfish,dog,cat"))

print(all_cats("cat,catfish"))

print(all_cats(""))

6 0
1 year ago
Marissa works at a company that makes perfume. She noticed many samples of the perfume were not passing inspection. She conducte
garik1379 [7]
Writing a business letter as if she gets her point across to the head of department then he could change the way they made the perfume so they would pass inspection and standard.
6 0
2 years ago
Read 2 more answers
Other questions:
  • A BCD code is being transmitted to a remote receiver. The bits are A3, A2, A1, and A0, with A3as the MSB. The receiver circuitry
    8·1 answer
  • Ajay wants to read a brief overview about early settlers in the United States. Which type of online text source should he most l
    9·2 answers
  • Multiple boolean expressions can be combined by using a logical operator to create ________ expressions.
    10·1 answer
  • Your computer is crashing on a regular basis. Which of the following is an operation available to the user that should help rese
    14·2 answers
  • What kind of device can monitor a connection at the demarc but cannot interpret data?
    9·1 answer
  • The ______ is the information center that drivers need to refer to when they're NOT scanning the road.
    7·1 answer
  • The kings and queens of England are listed in a relation Kings(name,nickname,house,beginReign,endReign). Their name is unique, e
    8·1 answer
  • ANSWER AS SOON AS POSSIBLE: When I try to join roblox adopt me it says: "Roblox Datastore servers are currently down. Please rej
    10·2 answers
  • Joe, Kate and Jody are members of the same family. Kate is 5 years older than Joe. Jody is 6 years older than Kate . The sum of
    11·2 answers
  • Which are types of lines? Choose three answers.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!