Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python The First Property: No Order

Why is order significant?

Why does order matter (or not matter, for that matter)? I'm only one video in and between lists, tuples, dictionaries and now sets I can hardly see what the differences are, aside from syntax.

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

Hey nicolaspeterson, the differences will become second nature the more you code. They each have specific uses, of course.

I usually the needs drive the choice from the main four Python containers:

  • need to contain stuff and reference items by the order the items are added. But slices are available, too: choose a list
  • I don’t care about order, but I want to look up items using a related unique key value (like value to color matching): choose a dict
  • but what if I want something like a list but something that is unchangeable after creation: choose a tuple
  • I like the uniqueness of the dict keys. Is there something that behaves like the dict keys but doesn’t have associated values? Choose a set

These four handle most of the common needs. But wait there’s more….

Check out the containers library module. It expands on the core list. I’ve used namedtuple(), deque, Counter, and defaultdict many times.

Post back if you need more help. Good luck!!!

Python really makes use of a lot of handy features. It's just a pain wrapping my head around it all.