Simple Efficient Python Solution Explained for both Beginners and Pros!
python\nclass Solution:\n    def displayTable(self, orders: List[List[str]]) -> List[List[str]]:\n        """\n        Function to take the list of orders made 
```python\nclass Solution:\n    def displayTable(self, orders: List[List[str]]) -> List[List[str]]:\n        """\n        Function to take the list of orders made by guests at various tables and produce a      final table wise invoice for the kitchen with count of all the dishes to be made for the evening for each table\n        """\n        \n        table_food_list = {}\n        # Declare a new menu\n        menu = set()\n        # Declare a new order invoice\n        invoice = dict()\n        \n        \n        # Aggregating the list of items to be produced for each table\n        \n        for order in orders:\n            # Unpack the entities for each order\n            _, table_no, food_item = order\n            # Add food item to the menu if it is already not present\n            menu.add(food_item)\n            # Check if we already took an order from that table\n            if table_no in invoice:\n                # Check if someone ordered the same dish from the table\n                if food_item in invoice[table_no]:\n                    # Increase the number of serving for that food item by 1\n                    invoice[table_no][food_item] += 1\n                else:\n                    # Add the first serving for that particular food item\n                    invoice[table_no][food_item] = 1\n            else:\n                invoice[table_no] = {food_item: 1}\n        \n        # Creating the output format for internal Invoice\n        \n        # Sorting the menu items alphabetically in a list\n        menu = list(menu)\n        menu = sorted(menu)\n        # Adding the column for table number\n        col_names = ["Table"] + menu\n        \n        \n        # Creating the final table wise invoice for each food item sorted alphabetically for food item and numerically for table number\n        final_invoice = [col_names]\n        # Scanning through the orders for each table\n        for table_no in sorted(invoice, key = int):\n            table_order = []\n            # First add the table number\n            table_order.append(table_no)\n            # Check the number of servings ordered for each food item in the menu\n            for food_item in menu:\n                # If the particular food item has been requested,add number of servings ordered\n                if food_item in invoice[table_no]:\n                    table_order.append(str(invoice[table_no][food_item]))\n                # Otherwise declare 0 servings to be made for that food item in current table\'s order summary\n                else:\n                    table_order.append("0")\n            # Add the current table\'s order summary to the final invoice to be used by the kitchen\n            final_invoice.append(table_order)\n        \n        # Send the final invoice to the kitchen\n        return final_invoice\n        \n```\n\n### Miscellaneous:\n\nIn an actual interview, I would further discuss how I can convert the original invoice into a data frame using pandas and use it for further analysis of customer ordering habits for the restaurant across various seasons or locations. Additionally, it could be used to create a dashboard for the kitchen for every 10 mins of orders\n\n```python\n"""\nInitial Steps for the above extended discussion\n"""\n\nimport pandas as pd\nfrom typing import List,Dict\n\ncurrent_orders = [["James","12","Fried Chicken"],["Ratesh","12","Fried Chicken"],["Amadeus","12","Fried Chicken"],["Adam","1","Canadian Waffles"],["Brianna","1","Canadian Waffles"]]\n\ndef displayTable(orders:List[List[str]])->Dict[str,Dict[str,int]]:\n        """\n        Function to take the list of orders made by guests at various tables and produce a      final table wise invoice for the kitchen with count of all the dishes to be made for the evening for each table\n        """\n        \n        table_food_list = {}\n        # Declare a new menu\n        menu = set()\n        # Declare a new order invoice\n        invoice = dict()\n        \n        \n        # Aggregating the list of items to be produced for each table\n        \n        for order in orders:\n            # Unpack the entities for each order\n            _, table_no, food_item = order\n            # Add food item to the menu if it is already not present\n            menu.add(food_item)\n            # Check if we already took an order from that table\n            if table_no in invoice:\n                # Check if someone ordered the same dish from the table\n                if food_item in invoice[table_no]:\n                    # Increase the number of serving for that food item by 1\n                    invoice[table_no][food_item] += 1\n                else:\n                    # Add the first serving for that particular food item\n                    invoice[table_no][food_item] = 1\n            else:\n                invoice[table_no] = {food_item: 1}\n\t\t\t\n\treturn invoice\n\ntable_orders  = display_table(current_orders)\n\ntable_orders_df = pd.DataFrame.from_dict(invoice,orient=\'index\')\n```\n\n#### Sample Dataframe Output:\n\n| | Fried Chicken |\tCanadian Waffles|\n|-----|------------|--------------------|\n|12|3.0|NaN|\n|1|Nan|2.0|\n\nOfcourse this needs some pre-processing such as:\n- Sort by column\n- Add name to first column\n- Replace Nan values by 0
[]