code: def sort_take(
      data_dict,
      sort_fn=None,
      sort_target="scores",
      reverse_results=False,
      top_n=None,
  ):
      if top_n is None:
          top_n = len(data_dict["scores"])
  
      if sort_fn is not None:
          scored_vals = list(map(sort_fn, data_dict[sort_target]))
          sort_indexes = np.argsort(scored_vals)[:top_n]
      else:
          sort_indexes = np.array(range(top_n))
  
      data_dict = data_dict.copy()
      for key in data_dict.keys():
          if key in [
              "names",
              "scores",
              "values",
              "left_names",
              "right_names",
          ]:
              if reverse_results:
                  data_dict[key] = [
                      data_dict[key][i] for i in reversed(sort_indexes)
                  ]
              else:
                  data_dict[key] = [
                      data_dict[key][i] for i in sort_indexes
                  ]
  
      return data_dict
  
imports: import plotly.graph_objs
  import numpy
  from plotly import subplots
  import matplotlib.pyplot
  from numbers import Number
  import logging
label_desc: Use image node_id 16 for calling a global function with example usage: sort_take(data_dict, sort_fn, sort_target, reverse_results, top_n) and returns: data_dict