Question

python

11.47 Lab Exam 3 - Column Sums This section has been set as optional by your instructor. Write a Python function column_sums(

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

#program to return the sum of list column contents

mylist=[[1,2,3],[1,2,3],[1,2]] #sample Nested list
li=[]    #creating empty list in which the sum of column content is to be appended

#Begning of the function

def column_sums(mylist):
for i in range(0,len(mylist),1): #iterating over nested list
li.append(sum(mylist[i]))    #appending the sum of column content to a new list
li.sort()     #sorting the list in ascending order to get he desired output
return li #return the single list

#printing the list and calling the function column_sums

print(column_sums(mylist))

Add a comment
Know the answer?
Add Answer to:
python 11.47 Lab Exam 3 - Column Sums This section has been set as optional by your instructor. Write a Python function...
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
  • PYTHON PLEASE!! Thank you in advance! 11.56 Lab Exam 3 - factors This section has been...

    PYTHON PLEASE!! Thank you in advance! 11.56 Lab Exam 3 - factors This section has been set as optional by your instructor Function Name: factors Parameters: int Returns: list of int Description: Write a function, factors, that takes an integer n, and returns a list of values that are the positive divisors of n. Note: 0 is not a divisor of any integer, 1 divides every number, and n divides itself Sample Inputs/Outputs: factors (49) Example Call: Expected Return: [7]...

  • Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as...

    Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as described below. Calls the function find_item_in_grid and prints the result. The find_item_in_grid function should have one parameter, which it should assume is a list of lists (a 2D list). The function should ask the user for a row number and a column number. It should return (not print) the item in the 2D list at the row and column specified by the user. The...

  • (Python) Write a program called sales.py that uses a list to hold the sums of the...

    (Python) Write a program called sales.py that uses a list to hold the sums of the sales for each month. The list will have 12 items with index 0 corresponds with month of “Jan”, index 1 with month “Feb”, etc. o Write a function called Convert() which is passed a string which is a month name (ex. “Jan”) and returns the matching index (ex. 0). Hint – use a list of strings to hold the months in the correct order,...

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • Write a function called find_max that takes a two-dimensional list as a parameter and returns the...

    Write a function called find_max that takes a two-dimensional list as a parameter and returns the number of the row that sums to the greatest value. For example, if you had the following list of lists: list = [[1, 2, 3], [2, 3, 3], [1, 3, 3]] The first row would be 6, the second 8 and the third 7. The function would, therefore, return 1. You can assume the passed in list of lists has at least one row...

  • Please use python 3 programming language Write a function that gets a string representing a file...

    Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...

  • Python 2.7 Write a function cumsum() that takes a list l as argument and returns the...

    Python 2.7 Write a function cumsum() that takes a list l as argument and returns the cumulative sum (also known as the prefix sum) of l, which is a list, say cs of the same length as l such that each element cs[i] is equal to the sum of the first i + 1 elements of l, i.e., cs[i] == l[0] + l[1] + l[2] + ... + l[i] You should not modify the argument list l in any way....

  • Write a Python function named print_nums that takes a single parameter, a list of float values,...

    Write a Python function named print_nums that takes a single parameter, a list of float values, and prints out the list on a single line.enclosed in brackets, each value with three places after the decimal point, the values separated by two spaces. You do not have to provide comments for this code. Example 1: print_nums([3/3, 4/3, 573, 6/3]) prints: [1.000 1.333 1.667 2.000] Example 2: print_nums([3]) prints: [3.000] Example 3: print_nums([]) prints: []

  • Can someone solve this practice exam question, python 3 5. (+15) Write a function bin 2dec...

    Can someone solve this practice exam question, python 3 5. (+15) Write a function bin 2dec ( ) that takes a string representation of any length binary number and returns the decimal equivalent without using any type conversions. Remember that the binary representation ofa number has a power of 2 in each position, starting with 2° in the right most position and increasing by 1 as it moves left (e.g. 222120) loina dec (nun det >>> bin2dec('110') 6 >>>bin2dec('11111111' )...

  • Write a function, sumdivisors, that takes a single integer parameter and returns the sum of all...

    Write a function, sumdivisors, that takes a single integer parameter and returns the sum of all the divisors of the parameter (including 1). So sumdivisors(6) will return 6 as 1+2+3=6. Note you may use a wrapper function or default parameters.

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