{"record":{"id":"c5918b1c2ad07fa1","repo":"TheAlgorithms/Python","slug":"the-elements-list-is-empty","errorCode":null,"errorMessage":"The Elements List is empty","messagePattern":"The Elements List is empty","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"data_structures/linked_list/from_sequence.py","lineNumber":48,"sourceCode":"        ...\n    ValueError: The Elements List is empty\n    >>> make_linked_list(())\n    Traceback (most recent call last):\n        ...\n    ValueError: The Elements List is empty\n    >>> make_linked_list([1])\n    <1> ---> <END>\n    >>> make_linked_list((1,))\n    <1> ---> <END>\n    >>> make_linked_list([1, 3, 5, 32, 44, 12, 43])\n    <1> ---> <3> ---> <5> ---> <32> ---> <44> ---> <12> ---> <43> ---> <END>\n    >>> make_linked_list((1, 3, 5, 32, 44, 12, 43))\n    <1> ---> <3> ---> <5> ---> <32> ---> <44> ---> <12> ---> <43> ---> <END>\n    \"\"\"\n\n    # if elements_list is empty\n    if not elements_list:\n        raise ValueError(\"The Elements List is empty\")\n\n    # Set first element as Head\n    head = Node(elements_list[0])\n    current = head\n    # Loop through elements from position 1\n    for data in elements_list[1:]:\n        current.next = Node(data)\n        current = current.next\n    return head\n","sourceCodeStart":30,"sourceCodeEnd":58,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/data_structures/linked_list/from_sequence.py#L30-L58","documentation":"from_sequence.make_linked_list raises ValueError('The Elements List is empty') when elements_list is falsy — empty list, empty tuple, or None. The builder needs at least one element because it immediately uses elements_list[0] as the head Node.","triggerScenarios":"make_linked_list([]), make_linked_list(()), or make_linked_list(None); feeding a generator-produced list that yielded nothing; passing a filtered result that happened to exclude all items.","commonSituations":"Building lists from query results or file lines where the source may legitimately be empty; defaults like make_linked_list(args.values or []) that collapse to empty; forgetting None is also rejected (falsy), not just [].","solutions":["Skip the call when the source is empty: 'if elements: head = make_linked_list(elements)'.","Substitute a default element if an empty chain must still be built.","Validate upstream producers so empty inputs are surfaced as their own error with context."],"exampleFix":"# before\nhead = make_linked_list(data)  # ValueError when data == []\n# after\nhead = make_linked_list(data) if data else None","handlingStrategy":"validation","validationCode":"head = make_linked_list(elements) if elements else None","typeGuard":"def is_buildable(seq) -> bool:\n    return bool(seq)  # rejects [], (), None","tryCatchPattern":"try:\n    head = make_linked_list(seq)\nexcept ValueError:\n    head = None  # empty input","preventionTips":["Check truthiness of the source sequence before building.","Handle None separately — it is also rejected.","Give empty sources their own early return with context in caller code."],"tags":["linked-list","value-error","empty-input","builder"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}