The only differences are that tuples are immutable and that lists have extra methods.

Is there ever a strong need for list-type data to be immutable? Evough to justify a whole extra data-type in the language?

Should they release a python 4 with it removed?

The only thing I can think of is as a default function parameter. This function is okay:

def dothings(a=(1,2)):
    print(a)
    a = (a[0], 3)

But this function misbehaves the second time it is called:

def dothings(a=[1,2]):
    print(a)
    a[1] = 3

But IMO the “mutable arguments” thing is another bug to be fixed in a hypothetical python 4. And even in python 3 you just write the function the recommended way, so there is not such a big problem.

def dothings(a=None):
    if a is None:
        a = [1, 2]
    print(a)
    a[1] = 3

The Python devs are clever guys though. There must be some really important reason to maintain both types?

  • roastpotatothief@lemmy.mlOP
    link
    fedilink
    arrow-up
    0
    ·
    3 years ago

    TBH I’m building up to a longer post, where I describe the (IMO) single major flaw in python, and how to fix it, and that this fix is not backward-compatible and justifies a new version number.

    • ksynwa@lemmy.ml
      link
      fedilink
      arrow-up
      0
      ·
      3 years ago

      Ah OK. Sorry for being an ass. I thought you were new to programming and dunning-kruger’d into a hasty opinion. Sorry for presuming.