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. val = L[row][col]
  20. if val < 0:
  21. neg.append(val)
  22. else:
  23. nonneg.append(val)
  24.  
  25. return (neg, nonneg)
Success #stdin #stdout 0.01s 7120KB
stdin
Standard input is empty
stdout
Standard output is empty