pastebin

Paste Search Dynamic
Recent pastes
get diagonal and non diagonal
  1. def get_diagonal_and_non_diagonal(L):
  2.     '''(list of list of int) -> tuple of (list of int, list of int)
  3.  
  4.    Return a tuple where the first item is a list of the values on the
  5.    diagonal of square nested list L and the second item is a list of the rest
  6.    of the values in L.
  7.  
  8.    >>> get_diagonal_and_non_diagonal([[1,  3,  5], [2,  4,  5], [4,  0,  8]])
  9.    ([1, 4, 8], [3, 5, 2, 5, 4, 0])
  10.    '''
  11.  
  12.     diagonal = []
  13.     non_diagonal = []
  14.     for row in range(len(L)):
  15.         for col in range(len(L)):
  16.  
  17.             if row == col:
  18.                 diagonal.append(L[row][col])
  19.  
  20.                 non_diagonal.append(L[row][col])
  21.  
  22.     return (diagonal, non_diagonal)
  23.  
  24.  
  25. print(get_diagonal_and_non_diagonal([[1,  3,  5], [2,  4,  5], [4,  0,  8]]))
Parsed in 0.012 seconds