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

> This always bugs me: why is `args` immutable (tuple) but `kwargs` mutable (dict)?

Because python didn’t (still doesn’t, but at this point even if it did backward compatibility would mean it wouldn’t be used for this purpose) have a basic immutable mapping type to use.

(Note, yes, MappingProxyType exists, but that’s a proxy without mutation operations, not a basic type, so it costs a level of indirection.)



In Python, except for mutability, is there any difference between tuple and list? In my experience: Pure Python people get so excited about tuples ("oh, it's so Pythonic"); others: much less.


> In Python, except for mutability, is there any difference between tuple and list? In my experience: Pure Python people get so excited about tuples ("oh, it's so Pythonic"); others: much less.

In my experience, people who don’t care about tuples are people who don’t understand them. It’s not much about being Pythonic or not (they exists in other languages) but rather about choosing the right data structure for solving your problem. Tuples are much more than a way of making immutable lists, they offer a type-safe and serializable representation of pairs and triplets; something you can’t have with a list. If you don’t use them yet, I really encourage you to document yourself (and again-- in general, not just in Python) because you’re missing something.


Generally tuples are an antipattern.


Hot take! Can you explain more? It might foster some good discussion. Also, how do you feel about the comments from the other "sister" post? They seem to be very keen about list vs tuple.




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

Search: