Concatenating Multiple Entries in a dict

WJG (16/03/21) This morning I needed to rework my copy of a translation dictionary with in excess of 160,000 entries. I have been using Metakit to store the data but needed to convert the data to a more portable form, a dict. Metakit is great, it allowed duplicate keys, so no problem so far, but then using a Tcl dict, the get operation will discard all but the last key. So, I needed to concatenate the multiple values and assign them to the same key.

Lets assume that this is representative of the problem.

set wordList {
a {1 one}
b {B}
c {C}
a {2 two}
a {3 three}
d {D}

Running the following snippet will append the multiple definitions to the same key:

set i 0
set myDict "{#META} {Monier-Williams Sanskrit-English Dictionary} "
foreach {k v} $wordList {
        if { [dict exists $myDict $k] } { 
                incr i 
                dict append myDict $k \n$v
        dict set myDict $k $v

In my sample data i, the total number of multiple definitions totalled 9490. So, such a simple piece of coding produces many blessings.

Don't you love Tcl for this sort of simplicity and power?