7. Dictionaries

When you have a collection of things like a list but you wish to give each item a unique name and then access those items by their names, it is best to arrange the values into a dictionary. Like lists, dictionaries can contain any number of values, such as numbers, people’s names, window names, channels, or command names. Dictionaries collect these values into a single entity that you can pass around like any other value, or nest inside other dictionaries or lists, and then you can retrieve those component values again by looking them up by their key name.

Dictionaries represent an ordered collection; dictionaries preserve the order of insertion of their keys and will iterate over them in that order. Dictionaries are represented ...

Get Tcl and the Tk Toolkit, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.