On Sun, Jul 27, 2014 at 11:49 AM, fl <rxjw...@gmail.com> wrote: > In Python, when should you use lists and when tuples? > > Sometimes you don't have a choice, for example if you have > > "hello %s you are %s years old" % x > then x must be a tuple. > > But if I am the one who designs the API and gets to choose the data types, > then > what are the guidelines?
You should use a tuple when you need something immutable (readonly), like a dictionary key. Immutable objects are good for hashing. You should use a list when you need something mutable (read/write), like appending over and over. Mutable objects are not good for hashing, because their hash value could change. -- https://mail.python.org/mailman/listinfo/python-list