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

> how does a tuple differ from a list and a dictionary in python

> A tuple is an immutable data structure in Python that stores key-value pairs. It is similar to a list, but it does not allow for any changes after it has been created. Tuples are represented by and lists by [].

This is not the whole answer given (it talks about dictionaries as well), but it's missing a few things that could be useful:

* It doesn't actually say what tuples are represented by (the characters seem to be stripped out)

* It doesn't show examples



Isn't that answer technically incorrect as well? A more precise answer would be that tuples can store key-value pairs, but even then I think that part of the answer is unnecessarily narrow.


Tuples are integer-indexed and contiguous in Python, you can't index them with strings, and you can't have sparse arrays.


I'm not sure how sparse arrays are relevant here?

But in any case, I guess I have to agree that integer indexing arguably counts as key-value pairs? It's definitely not the the first thing that comes to mind for me when describing them.


I'm arguing that key-value pairs are not a good way to think about tuples.


I'm definitely not going to disagree with you there.


Thanks for the example. We'll take a look.




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

Search: