Q:

Write a Python program to sum a specific column of a list in a given list of lists

0

Write a Python program to sum a specific column of a list in a given list of lists.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def sum_column(nums, C):
    result = sum(row[C] for row in nums)
    return result

nums = [
        [1,2,3,2],
        [4,5,6,2],
        [7,8,9,5],
        ]
print("Original list of lists:")
print(nums)

column = 0
print("\nSum: 1st column of the said list of lists:")
print(sum_column(nums, column))
column = 1
print("\nSum: 2nd column of the said list of lists:")
print(sum_column(nums, column))
column = 3
print("\nSum: 4th column of the said list of lists:")
print(sum_column(nums, column))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now