Thanks for all. Everything new to me is so amazing. Well, still a remaining question, how to sort based on the value of the key.
Actually I googled hours ago, wanna see more ways of doing it. Best regards, > > On 17 November 2011 14:04, lina <lina.lastn...@gmail.com> wrote: >> >> >> Traceback (most recent call last): >> >> File "<pyshell#292>", line 1, in <module> >> >> weight[list1[0]]=1 >> >> TypeError: unhashable type: 'list' >> > >> > You are trying to store a list as a key inside a dict. This cannot be >> > done >> > because lists (like all mutable types) can't be hashed. >> >> I checked online dictionary, still confused about hashed. is it equal >> to mix together or mess together? > > No.... you need to think programming/computer science where hash/hashing has > a different meaning. See wikipedia: > http://en.wikipedia.org/wiki/Hash_function > http://en.wikipedia.org/wiki/Hash_table > > Also see the description for "hashable" in the Python glossary: > http://docs.python.org/glossary.html#hashable > > Basically hashing is a way to convert something (often a string) into an > identifying number (not neccesarily but usually unique) in order to use this > number as a token for the original thing. Aside, you can infer that that > because the "dict" code complains about hashing implies that dicts > themselves are essentially implemented as hash tables... ;) > > HTH, > > Walter > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor