code: def order_dictionary(dictionary, mode, reverse=False):
      """
      Order a dictionary by 'key' or 'value'.
      mode should be either 'key' or 'value'
      http://stackoverflow.com/questions/613183/sort-a-python-dictionary-by-value
      """
  
      if mode == "key":
          return collections.OrderedDict(
              sorted(
                  dictionary.items(),
                  key=operator.itemgetter(0),
                  reverse=reverse,
              )
          )
      elif mode == "value":
          return collections.OrderedDict(
              sorted(
                  dictionary.items(),
                  key=operator.itemgetter(1),
                  reverse=reverse,
              )
          )
      elif mode == "key_value":
          return collections.OrderedDict(
              sorted(dictionary.items(), reverse=reverse)
          )
      elif mode == "value_key":
          return collections.OrderedDict(
              sorted(
                  dictionary.items(),
                  key=lambda x: (x[1], x[0]),
                  reverse=reverse,
              )
          )
      else:
          raise ValueError("Unknown mode. Should be 'key' or 'value'")
  
imports: import collections
  import datetime
  import os
  import operator
  import shutil
  import time
  import pickle
label_desc: Use image node_id 2 for calling a global function with example usage: order_dictionary(dictionary, mode, reverse) and returns: collections, collections, collections, collections