Question

The group_list function accepts a group name and a list of members, and returns a string...

The group_list function accepts a group name and a list of members, and returns a string with the format: group_name: member1, member2, … For example, group_list("g", ["a","b","c"]) returns "g: a, b, c". Fill in the gaps in this function to do that.

def group_list(group, users):
members=[]
members += "," .join(users)
  
return ("{}:{}".format(group,users))
print(group_list("Marketing", ["Mike", "Karen", "Jake", "Tasha"])) # Should be "Marketing: Mike, Karen, Jake, Tasha"
print(group_list("Engineering", ["Kim", "Jay", "Tom"])) # Should be "Engineering: Kim, Jay, Tom"
print(group_list("Users", "")) # Should be "Users:"

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

Please find the updated python code:

- Here, in the code we are using .join() which takes an iterable(in this case it is a List) and returns a String as a result, not an array.
i) So, I just removed the statement members=[]  from the code since it is of no use(You can keep this if you want But there won't be any error for this since anyhow in the next statement we are changing it).
ii) Also, I removed the appending symbol(+) because it will create an error saying Syntax error(Either you declare members as an array or as a string, both will create an error) Since you are getting a string as an output from the result of .join()

- Finally returning the modified string members not users along with the group as:
return ("{}:{}".format(group,members))
Since member is a list, It will simply again be the same as the input but with a semicolon in between group and users.

(I believe that you fully understand the code. If you still have any query, Feel free to drop me a comment below)

Program:

def group_list(group, users):
  
#Here the variable users is a list. so we are using join to take out each element from the list
# and join these elements with a comma(Since in the output there is a comma along with a space too)
members = ", " .join(users)
  
#Returing the string which consists of a variable group of string type as well as the members of string too
return ("{}: {}".format(group,members))
  
print(group_list("Marketing", ["Mike", "Karen", "Jake", "Tasha"])) # Should be "Marketing: Mike, Karen, Jake, Tasha"
print(group_list("Engineering", ["Kim", "Jay", "Tom"])) # Should be "Engineering: Kim, Jay, Tom"
print(group_list("Users", "")) # Should be "Users:"

main.py 4 1. def group_list(group, users): 2 3 #Here the variable users is a list. so we are using join to take out each elem

Output:

input Marketing: Mike, Karen, Jake, Tasha Engineering: Kim, Jay, Tom Users: ... Program finished with exit code o Press ENTER

Hope this Helps!!!
Please upvote as well, If you got the answer ?
If not please comment, I will Help you with that...

Add a comment
Know the answer?
Add Answer to:
The group_list function accepts a group name and a list of members, and returns a string...
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 program with a function that accepts a string as an argument and returns a...

    Write a program with a function that accepts a string as an argument and returns a copy of the string with the first character of each sentence capitalized. For instance, if the argument is “hello. my name is Joe. what is your name?” the function should return the string “Hello. My name is Joe. What is your name?” The program should let the user enter a string and then pass it to the function. The modified string should be displayed.

  • 1. String Length Write a function that returns an integer and accepts a pointer to a...

    1. String Length Write a function that returns an integer and accepts a pointer to a C-string as an argument. The function should count the number of characters in the string and return that number. Demonstrate the function in a simple program that asks the user to input a string, passes it to the function, and then displays the function’s return value. c++

  • Write a javascript function that accepts 3 arrays and returns a string of the elements sorted...

    Write a javascript function that accepts 3 arrays and returns a string of the elements sorted in ascending value, with duplicates removed. Return all alphabetic characters in lowercase. E.G. function([ 1,2,3, d], [5, 3, 0, ‘a’], [‘a’,’d’,9]) returns “0,1,2,3,5,9,a,d” E.G. function(['w', 'i', 'H', 5], [8, 5, 9, 'c', 'Z'], [6, 4, 'a', 'b', 'y']) returns “4,5,6,8,9,a,b,c,h,i,w,y,z” we must not use ' sort, remove, split,join and any built-in fucntions

  • Using Python code. Fill in the gaps in the nametag function so that it uses the...

    Using Python code. Fill in the gaps in the nametag function so that it uses the format method to return first_name and the first initial of last_name followed by a period. For example, nametag("Jane", "Smith") should return "Jane S." def nametag(first_name, last_name):    return("___.".format(___)) print(nametag("Jane", "Smith")) # Should display "Jane S." print(nametag("Francesco", "Rinaldi")) # Should display "Francesco R." print(nametag("Jean-Luc", "Grand-Pierre")) # Should display "Jean-Luc G."

  • Function name: triangular Parameters: integer Returns: a list Description: Write a function called triangular that accepts...

    Function name: triangular Parameters: integer Returns: a list Description: Write a function called triangular that accepts one integer parameter that returns a list with the same number of terms as the value of the parameter. If the parameter is zero or a negative number, you should return an empty list A triangular number is the sum of a positive integer and all the integers before it. The series is as follows: 1, 3, 6, 10, 15, 21,

  • HINT: USE def count_letters function: DO NOT use Length Function!!!!!!!!!!!!!!!!!!!!!!!! use string format to display percentage....

    HINT: USE def count_letters function: DO NOT use Length Function!!!!!!!!!!!!!!!!!!!!!!!! use string format to display percentage. "{:.1f}".format DO NOT USE ROUND PYTHON: Develop a program that asks the user to enter a text. The program should analyze the text and print out unique letters, in alphabetical order, with the percentage information of each letter. Case should be ignored. Write a function to analyze the text string. No global variables are used in the function. Function parameters must be used. Hint:...

  • 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...

  • 1.1. Write a function named "areFirstTwoTheSame AsLast TwoChars" that accepts a string. It returns true if...

    1.1. Write a function named "areFirstTwoTheSame AsLast TwoChars" that accepts a string. It returns true if the first two characters and the last two characters of the string are the same. It returns false otherwise. In addition, if the string is empty or has only one character, it also returns false. For example, these are the strings with their expected return values false falsc "AB" true "ABA" false "ABAB" trus "ABBA" false "ABCABC false "ABCCAB" true 1.2 Write a function...

  • python 3.7 write a function called read_file() which accepts a filename and returns a list of...

    python 3.7 write a function called read_file() which accepts a filename and returns a list of tuple objects. For example, if we have the following data: 0.000000000 192.168.0.24 10.0.0.5 H-NM 1.001451000 192.168.0.24 10.0.0.5 2.002970000 192.168.0.24 10.0.0.5 3.003552000 192.168.0.24 10.0.0.5 4.005007000 192.168.0.24 10.0.0.5 then the list should contain the following: [('192.168.0.24', 0, 84), ('192.168.0.24', 1, 84), ('192.168.0.24', 2, 84), ('192.168.0.24', 3, 84), ('192.168.0.24', 4, 84)] Note: • Each line consists of a number of fields separated by a single tab character....

  • Code the following function in JAVASCRIPT (Use of the given list of inbuilt functions is not...

    Code the following function in JAVASCRIPT (Use of the given list of inbuilt functions is not allowed) Write a function that searches the string (passed as first argument) for the character (passed as second argument) and changes the case for all instances of that char found in string. The function should return the new string as shown in example below: function(‘abRA’, ‘a’) // returns ‘AbRa’ Assignment-2(2).pdf + х A file:///C:/Users/bhati/OneDrive/Desktop/Assignment-2(2).pdf 5 of 6 O + Fit to page IL Page...

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