Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

They are, but it's shallow:

    >>> x = ([1,2,3,4],"whatever")
    >>> x[0].append('z')
    >>> x
    ([1, 2, 3, 4, 'z'], 'whatever')
And python gives you access to anything:

    >>> def gotcha():
    ...      z = globals()['x']
    ...      z = list(z)
    ...      z.append("I've seen'em do it man!")
    ...      globals()['x'] = tuple(z)
    ... 
    >>> x = (1,2,3,4)
    >>> gotcha()
    >>> x
    (1, 2, 3, 4, "I've seen'em do it man!")


It be shallow with a Singly Linked List too no? What inherently makes a Singly Linked List better at addressing this problem if it contains mutable elements?


Typically, in a functional language, values are immutable. So if you cons to a list, you create a new value that has the current list as its tail. Since all lists are immutable, they can be shared and there's no need for a deep copy.

Python is not a functional programming language....




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: