[Tutor] how to understand unhashable type: 'list'
Alan Gauld
alan.gauld at btinternet.com
Fri Nov 18 01:19:30 CET 2011
On 17/11/11 15:30, lina wrote:
> tuple (which I don't understand).
You mean you don't understand the term 'tuple'?
Basically its just a collection of data.
You can get a
triple - 3 items,
a quadruple - 4 items,
quintiple - 5 items etc
The generic term for a collection of N items is a tuple.
triple, quadruple, etc are all specific types of tuple.
It's a math thing...
In python a tuple is just lie a list except you can't
change it - ie. it is immutable. This makes it perfect
for using as a key in a dictionary when you'd like to
use a list...
As an aside some folks like to distinguish between tuples and lists by
suggesting that tuples can hold collections of different types of data:
t = (1,'two', 3.0) whereas lists should only hold items of the same type.
L = [1,2,3]
But that's a semantic nicety, Python doesn't make any such distinction.
And for dictionary keys (1,2,3) is the only way to do it...
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list