Let me take this one step further. If the data you’re working with is really complex, you might want to define custom classes. This gives your code more structure and makes it much easier to manage and understand over time.
from typing import List
class Node:
def __init__(self, node_id: str, node_name: str, uptime_minutes: int):
self.node_id = node_id
self.node_name = node_name
self.uptime_minutes = uptime_minutes
def get_nodes() -> List[Node]:
return [Node("node1", "Node 1", 120), Node("node2", "Node 2", 300)]
Using custom classes not only improves readability but also allows you to add methods and validations, making your code more robust and future-proof.