Re: dictionaries?
- To: mathgroup at smc.vnet.net
- Subject: [mg20475] Re: dictionaries?
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Wed, 27 Oct 1999 02:04:44 -0400
- References: <7v3bov$5tg@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Joe Strout <joe at strout.net> wrote in message news:7v3bov$5tg at smc.vnet.net... > In Python, there's an extremely handy datatype called a "dictionary" > which implements a many-to-1 mapping between keys (which can be any > hashable type) and values (which can be anything). E.g.: > > > d = {"one":1, "two":2} > > d["one"] > 1 > > d["three"] > (key not found) > > I'm looking for something similar in Mathematica -- it's a great way to > organize lists of parameters, without having to worry about the order > in which they are listed. > > I've searched the online help and flipped through the Mathematica book, > but I can't find anything like this. Have I missed something? > > Thanks, > -- Joe > > -- > ,------------------------------------------------------------------. > | Joseph J. Strout Biocomputing -- The Salk Institute | > | joe at strout.net http://www.strout.net | > `------------------------------------------------------------------' > Check out the Mac Web Directory! http://www.strout.net/macweb.cgi > Joe, I'm not sure that I understand what you want, but the use of options (such as for Plot) in Mathematica avoids needing to enter in a definite order. For example g[x_, opts___?OptionQ] := A[x, B] /. {opts}; g[3, A -> a, B -> b] a[3, b] g[3, B -> b, A -> a] a[3, b] -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565