{"record":{"id":"3fbefc9417dac643","repo":"TheAlgorithms/Python","slug":"the-elements-list-is-empty-3fbefc","errorCode":null,"errorMessage":"The Elements List is empty","messagePattern":"The Elements List is empty","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"data_structures/linked_list/print_reverse.py","lineNumber":103,"sourceCode":"            self.append(item)\n\n\ndef make_linked_list(elements_list: Iterable[int]) -> LinkedList:\n    \"\"\"Creates a Linked List from the elements of the given sequence\n    (list/tuple) and returns the head of the Linked List.\n    >>> make_linked_list([])\n    Traceback (most recent call last):\n        ...\n    Exception: The Elements List is empty\n    >>> make_linked_list([7])\n    7\n    >>> make_linked_list(['abc'])\n    abc\n    >>> make_linked_list([7, 25])\n    7 -> 25\n    \"\"\"\n    if not elements_list:\n        raise Exception(\"The Elements List is empty\")\n\n    linked_list = LinkedList()\n    linked_list.extend(elements_list)\n    return linked_list\n\n\ndef in_reverse(linked_list: LinkedList) -> str:\n    \"\"\"Prints the elements of the given Linked List in reverse order\n    >>> in_reverse(LinkedList())\n    ''\n    >>> in_reverse(make_linked_list([69, 88, 73]))\n    '73 <- 88 <- 69'\n    \"\"\"\n    return \" <- \".join(str(line) for line in reversed(tuple(linked_list)))\n\n\nif __name__ == \"__main__\":\n    from doctest import testmod","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/data_structures/linked_list/print_reverse.py#L85-L121","documentation":"print_reverse.make_linked_list raises a generic Exception('The Elements List is empty') for falsy input, same contract as from_sequence but a different exception type (Exception vs ValueError). The returned LinkedList feeds in_reverse, which itself handles the truly empty list fine (returns '').","triggerScenarios":"make_linked_list([]) or make_linked_list(()) — exactly the doctest case; passing None; passing a sequence after a filter/comprehension that removed everything.","commonSituations":"Splitting a string into tokens and getting zero tokens; processing optional CLI arguments where the user supplied none; mixing this builder with from_sequence's and assuming both raise ValueError (they do not).","solutions":["Check truthiness of the sequence before calling: 'if elements_list:'.","If an empty LinkedList is acceptable, construct LinkedList() directly and skip the builder.","Catch generic Exception and match the message if the empty case must be normalized."],"exampleFix":"# before\nll = make_linked_list(tokens)  # Exception when tokens == []\n# after\nll = make_linked_list(tokens) if tokens else LinkedList()","handlingStrategy":"validation","validationCode":"ll = make_linked_list(elements) if elements else LinkedList()","typeGuard":"def is_buildable(seq) -> bool:\n    return bool(seq)","tryCatchPattern":"try:\n    ll = make_linked_list(seq)\nexcept Exception as e:\n    if 'The Elements List is empty' not in str(e):\n        raise\n    ll = LinkedList()","preventionTips":["This builder raises bare Exception, unlike from_sequence's ValueError — catch accordingly.","in_reverse already handles LinkedList() gracefully, so building an empty one is fine.","Validate filtered/derived sequences for emptiness before passing."],"tags":["linked-list","empty-input","builder","generic-exception"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}