Demo result
Asia China Beijing India New Delhi Japan Tokyo Europe England London France Paris Germany Berlin Russia Moscow North America Canada Ottawa Mexico Mexico City USA Washington South America Brazil Brasilia
Demo source
# create the rich list richlist create countries -country "" -continent "" -capital "" # fill the rich list set list \ { {-country Brazil -continent "South America" -capital Brasilia} {-country Canada -continent "North America" -capital Ottawa} {-country China -continent Asia -capital Beijing} {-country England -continent Europe -capital London} {-country France -continent Europe -capital Paris} {-country Germany -continent Europe -capital Berlin} {-country India -continent Asia -capital "New Delhi"} {-country Japan -continent Asia -capital Tokyo} {-country Mexico -continent "North America" -capital "Mexico City"} {-country Russia -continent Asia -capital Moscow} {-country USA -continent "North America" -capital Washington} } foreach item $list { countries add [eval countries create $item] } # update an item [countries ref (-country|Russia)] config -continent Europe # display the countries by continent # create an index countries index create -continent # go thru all continents foreach continent [countries values -continent] \ { # get continent subset set sublist($continent) [countries selection -continent $continent] # display continent name puts $continent # sort continent sublist by countries & capitals names $sublist($continent) sort {-country -capital} -dictionary # display continent countries & capitals names puts [$($continent) foreach item { $item cget -country -capital } \ \n {\t\t%-10s%s}] }