fork download
  1. def get_negative_nonnegative_lists(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 negative ints in the
  5. inner lists of L and the second item is a list of the non-negative ints
  6. in those inner lists.
  7.  
  8. Precondition: the number of rows in L is the same as the number of
  9. columns.
  10.  
  11. >>> get_negative_nonnegative_lists([[-1, 3, 5], [2, -4, 5], [4, 0, 8]])
  12. ([-1, -4], [3, 5, 2, 5, 4, 0, 8])
  13. '''
  14.  
  15. nonneg = []
  16. neg = []
  17. for row in range(len(L)):
  18. for col in range(len(L)):
  19. if L[row][col] < 0:
  20. neg.append(L[row][col])
  21. elif L[row][col] >= 0:
  22. nonneg.append(L[row][col])
  23.  
Success #stdin #stdout 0.01s 7140KB
stdin
Standard input is empty
stdout
Standard output is empty