Python #7 - Other data structures

posted in Programmology
Published April 21, 2005
Advertisement
I just read about 3 other data structures in Python: Tuples, Sets, and Dictionaries.

Sets and Dictionaries are pretty straightforward- a set is an unordered sequence of unique elements, and a dictionary is a sequence of key-value pairs.

But a tuple? What is the difference of a tuple and a list? The only difference I can see is that tuples are enclosed in parentheses and lists are enclosed in brackets. Also that tuples are immutable. Otherwise, indexing, slicing, etc. operations are the same. Maybe those are the only differences. Technically I know the difference but Python doesn't seem to differentiate them too much.
0 likes 2 comments

Comments

Brandon N
Tuples, unlike lists, can be used as dictionary keys, which have to be immutable.

Should a value not be changed, it's generally stored in a tuple, though that's more of an implication of use rather than a rule for obvious reasons.
April 21, 2005 09:23 PM
okonomiyaki
Ah, I see. I suppose that's a pretty big difference, and could be important in cases such as dictionary keys.

Cool man. Thanks for all your comments!
April 21, 2005 11:38 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement