Write a Python program to sum a specific column of a list in a given list of lists
- برمجة
- برمجة بايثون
- 2021-04-16
- salsabeelalhams99111801528
الأجوبة
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))أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال