from typing import OrderedDict


def job_list_table_format(result):
    """Format job list as a table."""
    table = []
    for item in result:
        row = OrderedDict()
        row['Name'] = item['name']
        row['Resource Group'] = item['resourceGroup']
        cluster = item['cluster']['id'].split('/')[8]
        row['Cluster'] = cluster
        row['Cluster RG'] = item['cluster']['resourceGroup']
        row['Tool'] = item['toolType']
        row['Nodes'] = item['nodeCount']
        row['State'] = item['executionState']
        if item['executionInfo'] and \
           item['executionInfo']['exitCode'] is not None:
            row['Exit code'] = str(item['executionInfo']['exitCode'])
        else:
            row['Exit code'] = ''
        table.append(row)
    return table