Sum of diagonal elements using Comprehension


Write a program to find the sum of diagonal elements in a matrix.



Comprehensions provide a concise way to create new set of elements that satisfy a given condition from an iterable. Here the iterable is the for loop looking for diagonal elements. The list thus formed is passed to sum which returns the sum of elements in the list.




Leave a Reply

bodrum escort - eskişehir esc - mersin escort - mersin escort bayan - mersin esc