What we basically understand by hash is that
its a variable or more technically a
data structure which contains only two columns and can have many more rows of data.
see the below pic, i hope you will be able to understand.
So,
1. when you call only
scores.keys() and assign it to each_score; the values (8.65, 9.12, ....) stored in keys are assigned to each_score, and as they are linked/pointed to names of surfers they will be printed by scores[each_score].
Note: Here the values(8.65, 9.12, ....) are itself keys, i.e., they are unique for each surfer(here it was assumed, but it may fail in cases where the scores of two surfers are equal).
2. when you call only
scores.values() and assign it to each_score; only surfers names will be displayed and it will not be possible to access the scores of each surfers.
3. when you call
scores.items() and assign it to each_score; it returns lists of pair of keys and values,i.e., surfer names and his/her score will be returned in pair to the variable each_score.
note: try displaying the variable each_score by using "print (each_score)" in the last for loop.
u can read more about the hash/dictionary data structure, different kind of operations on it and its properties in the below link.
link to hash
This post has been edited by #TM#: 02 January 2013 - 04:52 AM