input: Write a python function to find the top 3 frequent items for each group in a DataFrame using a specified key.
  assert top_frequent(df, 'category') == [('A', ['apple', 'banana', 'cherry']), ('B', ['berry', 'kiwi', 'mango'])]
  assert top_frequent(df, 'type') == [('X', ['item1', 'item2', 'item3']), ('Y', ['item4', 'item5', 'item6'])]
  assert top_frequent(df, 'group') == [('G1', ['thing1', 'thing2', 'thing3']), ('G2', ['thing4', 'thing5', 'thing6'])]
output: def top_frequent(df, key):
      def get_top_3_items(sub_df):
          return sub_df.value_counts().nlargest(3).index.tolist()
      
      result = []
      for group, group_df in df.groupby(key):
          top_items = get_top_3_items(group_df.iloc[:, 1])
          result.append((group, top_items))
      
      return result