Python simple solution with defaultdicts with comments
tedious question\n\nyou could condense the final two for loops when building the result table but I find this easier to read\n\npython\ndef displayTable(self, o
tedious question\n\nyou could condense the final two for loops when building the result table but I find this easier to read\n\n```python\ndef displayTable(self, orders: List[List[str]]) -> List[List[str]]:\n        dict_ = defaultdict(lambda: defaultdict(int)) # nested dictionary of [table][item] storing counts\n        items = sorted(set(item for name,table,item in orders)) # unique items sorted lexicographically\n        tables = sorted(set(table for name,table,item in orders), key=int) # unique table numbers sorted\n        \n        # build dictionary\n        for name,table,item in orders:\n            dict_[table][item] += 1\n        \n        # build result table row/column headers\n        res = [[\'Table\']+items]\n        for table in tables:\n            res.append([table])\n            \n        # append each value to result table based on row/column headers\n        for i in range(1, len(res)):\n            for j in range(1, len(res[0])):\n                table, item = res[i][0], res[0][j]\n                count = str(dict_[table][item])\n                res[i].append(count)\n        \n        return res\n```
['Python', 'Python3']