Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: Rui Maciel Newsgroups: comp.programming Subject: Re: Generating multi-level associative arrays Date: Sun, 23 Jun 2013 08:30:53 +0100 Organization: A noiseless patient Spider Lines: 18 Message-ID: References: Reply-To: rui.maciel@gmail.com Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit Injection-Date: Sun, 23 Jun 2013 07:25:43 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="f9db22b05a10709939588f9f492c811f"; logging-data="1667"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Xk+UG2zODM9dFWLm7AtBJRywVAv5mcx0=" User-Agent: KNode/4.8.5 Cancel-Lock: sha1:4+1XvYhSS9ow7swxCbz7xE9Z/PQ= Xref: csiph.com comp.programming:3528 Victor Porton wrote: > But what is the best way to do this if we want a MULTILEVEL associative > array? (indexed by first key "a", then by key "b", etc.) > > I want to discuss the most elegant, short, and practical solution for this > kind of problems. I don't know if it's the most elegant, but if you wish to have multiple keys map to a value then you can resort to a tuple containing both keys as your map's key. That approach is very common. For example, with the "dictionary of keys" matrix data structure, the matrix elements are stored in a key:value pair whose key is a (row, column) tuple. Hope this helps, Rui Maciel