Re: dictionaries?
- To: mathgroup at smc.vnet.net
- Subject: [mg20608] Re: dictionaries?
- From: "John M. Jowett" <John.Jowett at cern.ch>
- Date: Thu, 4 Nov 1999 02:13:27 -0500
- Organization: CERN
- References: <7v3bov$5tg@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Joe Strout wrote: > > 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 Depending on exactly what you want to do, Mathematica's rules may be fit the bill, e.g., define a named set of rules d = {one->1,two->2} then you can have things like In[6]:= x[one] /. d Out[6]= x[1] In[8]:= two + three /. d Out[8]= 2 + three Rules are often a handy one to store a set of substitutions. John Jowett -- ---------------------------------------------------------------------- My home page: http://wwwslap.cern.ch/~jowett/ ----------------------------------------------------------------------