62

Variables
Associative Array Exercise

  • Two more common applications for associative arrays are

    • Finding a subset of unique items in a list

    • Counting the number of instances of items in a list

  • Your task is to start with the "unique" example script as a template to create a script called "count" as described above


    Exercise
    1. Run the "unique" example like this: unique < unique.dat
      (or you can type one word per line as input on your keyboard)
    2. Copy the "unique" example into a new script file called "count".
    3. Modify it to count the number of instances of items in a list
      • HINT1: You can use the += operator to add to a value.
      • HINT2: Print both the KEY and the VALUE for each key.

    Start

    Solution