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

how much more efficient are tuples than lists? 2x? 10x? etc.?

The course mentions tuples are more efficient than lists. how much more?

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

That is an awesome question for a programmer to ask-- I like that you are thinking about this as it seems not many consider the amount of memory their programs consume! Mainly we try to get our programs running, and then solve the efficiency problems later. :-)

The primary difference between lists and tuples is that lists are mutable objects and tuples are immutable objects.

This has lots of implications--

Due to the way Python is implemented, Tuples are more memory efficient than lists because they don't have to be changed or rearranged, or copied, thus there are fewer memory references that have to be used to handle each tuple. Each tuple only needs to be represented ONCE!

The time advantage for handling can be demonstrated using profiling tools-- again, hands down tuples are more efficient.

I will refer you to this stack overflow post that says it much better than I can.

https://stackoverflow.com/questions/68630/are-tuples-more-efficient-than-lists-in-python

Good luck with your Python journey!