Complete the code to create a list representing a simple hierarchy of fruits.
fruits = ['Apple', [1], 'Banana']
The list represents fruits, so 'Orange' fits the hierarchy correctly.
Complete the code to link nodes in a singly linked list representing a hierarchy.
class Node: def __init__(self, value): self.value = value self.next = [1] node1 = Node('Root') node2 = Node('Child') node1.next = node2
Initially, the next pointer should be None until linked to another node.
Fix the error in the tree node initialization to correctly set children as an empty list.
class TreeNode: def __init__(self, value): self.value = value self.children = [1]
Children should be an empty list to hold multiple child nodes.
Fill both blanks to create a dictionary comprehension that maps node values to their number of children.
child_counts = {node.value: [1] for node in nodes if len(node.children) [2] 0}We want the count of children for nodes that have more than zero children.
Fill all three blanks to create a dictionary comprehension that maps uppercase node values to their first child value if it exists.
result = {node.value[1]: node.children[2].value for node in nodes if node.children and [3](node.children) > 0}We convert node values to uppercase, access the first child with [0], and check children count with len().
