News for hackers. Stuff that matters.
Re:Show HN: Refurb – A tool for refurbishing and modernizing... by dragonwriter on Wednesday September 28, 2022 @02:00PM (#33011060)
> Tuples are not just immutable lists

They aren’t just immutable lists logically, but since Python (while it can use a static typechecker for verifying correctness to some extent) doesn’t use type information about what is stored in containers for storage implementation, effectively at runtime they are just immutable lists.

But, even logically, and apart from that implementation consideration, immutable lists are one of the things they are, are intended to be, ans are designed to be used for.

> They're for heterogeneous collections and are meant to be destructured or otherwise have their elements acted on individually.

That is another use case, yes. The existence of that use case does not negate the immutable list use case.

> It looks different -- why?

tuple type hints have a form (that you point out) for homogenous arbitrary length immutable lists as well as one for fixed-length potentially-heterogenous ordered collections because tuples are intended to serve both purposes, not just the latter.

> It's also why there's list comprehension but no tuple comprehension.

No, genexps using () and having broader utility is why there are no tuple comprehensions. Heck, if genexps were around first, we might not have list, set, or dictionary comprehensions, either.

There are no comments on this comment yet.