是否可以通过嵌套循环中的函数 return (HELP)

Is it possible to return by a function from nested loop (HELP)

I am trying to return from function 'letter' the following output as shown on image

你是这个意思吗?

v = [['a', 'b', 'c'], ['a', 'f', 'g'], ['h', 'i', 'j']]


def letter(n):
  res = []
  for item in v:
    if n in item:
      res.append(item)
  return res


print(letter('a'))  # [['a', 'b', 'c'], ['a', 'f', 'g']]