Is a tuple actually faster than a list? OLOllieGrantOP 7 Oct, 12:02 The example says tuples are lighter. Should I convert my lists to tuples for speed?
AMAmeliaRuns7 Oct, 15:10replies: 2Technically tuples are a bit smaller in memory and slightly faster to create, but the difference is tiny for normal programs. Choose by meaning, not speed:- list: a collection that can grow or change- tuple: a fixed group of values (like a record)
JAJackStack8 Oct, 07:52Tried it: 88 vs 64 bytes here. Fun to see but yeah, doesn't matter for my scripts.
HEHenryWrites7 Oct, 21:56import sys; sys.getsizeof([1,2,3]), sys.getsizeof((1,2,3)) if you're curious about the sizes.
Comments 4
Join the discussion CommentAlready have an account? Log in
Technically tuples are a bit smaller in memory and slightly faster to create, but the difference is tiny for normal programs. Choose by meaning, not speed:
- list: a collection that can grow or change
- tuple: a fixed group of values (like a record)
Ok, so no premature optimisation. Got it.
Tried it: 88 vs 64 bytes here. Fun to see but yeah, doesn't matter for my scripts.
import sys; sys.getsizeof([1,2,3]), sys.getsizeof((1,2,3))if you're curious about the sizes.