code: def order_by_header(table, headers):
      '''Convert a list of dicts to a list or OrderedDicts ordered by headers'''
      ordered_table = []
      for row in table:
          # Tricky list comprehension got tricky when needing special handling
          # Lets do this the simplest way we can:
          row = {k:v for k,v in row.items() if k in headers}
          for h in headers:
              if h not in row:
                  row[h] = ''
          ordered_row = OrderedDict(sorted(row.items(),
                                           key=lambda x:headers.index(x[0])))
          ordered_table.append(ordered_row)
      return ordered_tablf order_by_header(table, headers):
      '''Convert a list of dicts to a list or OrderedDicts ordered by headers'''
      ordered_table = []
      for row in table:
          # Tricky list comprehension got tricky when needing special handling
          # Lets do this the simplest way we can:
          row = {k:v for k,v in row.items() if k in headers}
          for h in headers:
              if h not in row:
                  row[h] = ''
          ordered_row = OrderedDict(sorted(row.items(),
                                           key=lambda x:headers.index(x[0])))
          ordered_table.append(ordered_row)
      return ordered_table
docs: Convert a list of dicts to a list or OrderedDicts ordered by headers