Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Python #7 - Other data structures

Sign in to follow this  


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.
Sign in to follow this  


Recommended Comments

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.

Share this comment

Link to comment
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!

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!