Associate a key with a value using a hash

Start with an empty hash:

An hash <s assied to a variable tailed "scores ote ^e use of C.rly brackets here.

The keys go here-

The keys go here-

The values go here.

You add data to an existing hash by describing the association between the key and the value. Here's how to associate a surfers' name with their score:

Put the key inside the square braCkets... scores[8.45] = 'Jo^ph'

A new row of data is added to the hash- Note the association.

A new row of data is added to the hash- Note the association.

..and put the vaWe to the right of the assignment operator-

Note how the act of assigning a value to a key CREATES the hash entry (assuming it's not already there). In Python, there's no explicit "appendO" method for hashes as there is for arrays.

iterate hash data

Was this article helpful?

0 0

Post a comment