While studying linked lists from - https://composingprograms.com/pages/23-sequences.html#linked-lists
empty ='empty'
four = [1, [2, [3, [4, 'empty']]]]
x = [1,2];
def is_link(s):
"""s is a linked list if it is empty or a (first, rest) pair."""
return s == empty or (len(s) == 2 and is_link(s[1]))
print(is_link(four))
print(is_link(x))
The program recognizes four as a linked list, But when i plug in x it returns an error instead of returning "False".
If i change value of x to just [1] or [1,2,3] it returns as expected, but if i enter a normal list [1,2] with 2 values i run into this error. .Why is this?