code: def _flatten(instances):
      """Flatten iterator"""
      # Flattened version
      if isinstance(instances, list):
          flattened = [
              (None, name, est) for name, est in sorted(instances)
          ]
      else:
          # Compress dictionary and sort on case_est keys
          vps = [
              ("%s__%s" % (case, est_name), est)
              for case, instance_list in instances.items()
              for est_name, est in instance_list
          ]
          flattened = [
              (name.split("__")[0], name.split("__")[1], est)
              for name, est in sorted(vps)
          ]
      return flattened
  
file_path: mlens/mlens/utils/formatting.py
imports: from __future__ import division, print_function
  from collections import Counter
  from .checks import assert_valid_estimator, assert_correct_format
  from .exceptions import LayerSpecificationError
  from ..externals.sklearn.base import clone
label_desc: Use image node_id 6 for calling a global function with example usage: _flatten(instances) and returns: flattened