Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
Chris Freeman
Treehouse Moderator 67,736 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.