Is a tuple actually faster than a list?

OllieGrantOP

The example says tuples are lighter. Should I convert my lists to tuples for speed?

9

Comments 4

Join the discussion

Already have an account? Log in

  1. AmeliaRunsreplies: 2

    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)

    6
      1. JackStack

        Tried it: 88 vs 64 bytes here. Fun to see but yeah, doesn't matter for my scripts.

        1
    1. HenryWrites

      import sys; sys.getsizeof([1,2,3]), sys.getsizeof((1,2,3)) if you're curious about the sizes.

      3